I roll my own elem
function called elem'
elem' :: (Eq a) => a -> [a] -> Bool
elem' n ys = foldl (\acc p -> if (p == n) then True else False) False ys
Seems to work but I want to quickCheck it in GHCi so I import Test.QuickCheck
verboseCheck (\a -> (\xs ->( (elem' a xs) == (elem a xs)) ) )
Without a type declaration on the test function it tests ok, but that's because it's only testing null inputs.
Something is wrong with my type declaration for the test function:
verboseCheck (\a->(\xs->((elem' a xs)==(elem a xs))) :: Int->[Int]->Bool)
verboseCheck (\a->(\xs->((elem' a xs)==(elem a xs))) :: Char->[Char]->Bool)
Error for first one:
• Couldn't match expected type ‘[Int] -> Bool’
with actual type ‘Bool’
• Possible cause: ‘(==)’ is applied to too many arguments
In the expression: ((elem' a xs) == (elem a xs))
In the expression:
(\ xs -> ((elem' a xs) == (elem a xs))) :: Int -> [Int] -> Bool
In the first argument of ‘verboseCheck’, namely
‘(\ a
-> (\ xs -> ((elem' a xs) == (elem a xs))) ::
Int -> [Int] -> Bool)’
<interactive>:258:39: error:
• Couldn't match expected type ‘[()]’ with actual type ‘Int’
• In the second argument of ‘elem'’, namely ‘xs’
In the first argument of ‘(==)’, namely ‘(elem' a xs)’
In the expression: ((elem' a xs) == (elem a xs))
<interactive>:258:54: error:
• Couldn't match expected type ‘[()]’ with actual type ‘Int’
• In the second argument of ‘elem’, namely ‘xs’
In the second argument of ‘(==)’, namely ‘(elem a xs)’
In the expression: ((elem' a xs) == (elem a xs))
if E then True else False
is usually writtenE
.if (p == n) then True else False
-->p == n
.