So, I'm following the tutorial. Teach you Haskell for Great Good! , and so far I absolutely love Haskell. But in one of the functions mentioned in the tutorial, I get a warning that the if statement is redundant.
Edit: Let me understand that the purpose of the function is to act in exactly the same way as the elem function (the one provided by default by Haskell).
Here's the original function:
elem' :: (Eq a) => a -> [a] -> Bool elem' y ys = foldl (\acc x -> if x == y then True else acc) False ys
Initially, there were two warnings: one was a decrease in eta, so I removed ys from the beginning and end of the function name to get:
elem' :: (Eq a) => a -> [a] -> Bool elem' y = foldl (\acc x -> if x == y then True else acc) False
Now I tried to reduce the function to the following, and this leads to an error:
elem' :: (Eq a) => a -> [a] -> Bool elem' y = foldl (\acc x -> x == y)
I think I'm just very new to Haskell and don't see the obvious solution. Can someone tell me which code change will work correctly and still remove the compiler warning?
source share