How do I put a boolean into a list and output it in Haskell?

So I am new to Haskell and below I have attempted to program a function that takes a given value of e and a given list and determines whether that given value appears in the list given outputting True if the value given does appear and False if not.

inListm e [] = False 
inListm e (x:xs)
 | e == x = True || inListm e xs
 | otherwise = False || inListm e xs 


inListm 2 [0, 2, 1, 2] 

is given, the output would be


However, I would like the final output to be in a list like this


I have attempted to do this by

inListd e [] =  False : []
inListd e (x:xs)
  | e == x = True : [] || inListd e xs
  | otherwise = False :[]  || inListd e xs 

but all that gives me is an error so I would like to know how I could resolve this

>Solution :

You are on the right track. The only thing necessary is to return a list if you have a result, so:

inListd :: Eq a => a -> [a] -> [Bool]
inListd e [] = [False] 
inListd e (x:xs)
 | e == x = [True]
 | otherwise = inListd e xs

That being said, I does not seem to make much sense to wrap the result in a list.

Leave a Reply