[Haskell-beginners] foldl on Bool:s

goforgit . teztingit at gmail.com
Thu Sep 24 16:04:18 UTC 2015


Reading http://learnyouahaskell.com/higher-order-functions

I understand that with the function

sum' :: (Num a) => [a] -> a
sum' = foldl (+) 0

the call

ghci>>> sum' [1,2,3]

will be evaluated as

0 + 1 + 2 + 3 = 6

But what about the function

elem' :: (Eq a) => a -> [a] -> Bool
elem' y ys = foldl (\acc x -> if x == y then True else acc) False ys

and calling it with

ghci>>> elem' 3 [1,2,3]

How is that evaluated to True by foldl in elem'?

Thanks in advance for any explanation to this!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150924/8ddc1d38/attachment.html>


More information about the Beginners mailing list