Nov 25, 2011

Learn Me a Haskell

* f a is like f(a) in Java/C,
* map f [a, b] is the same as [f a, f b],
* a $ b $ c the same as a (b c),
* (f . g) x is the same as f (g x),
* digitToInt '1' == 1,
* "hi" == ['h', 'i'], and
* show 100 == "100".

So, all these expressions evaluate to 6:

Prelude Data.Char> all (==6) [
sum (map digitToInt (show 123)),
sum $ map digitToInt $ show 123,
sum . map digitToInt $ show 123,
(sum . map digitToInt . show) 123]
True
It's surprising is how simple the definition for $ is:
f $ x = f x

0 comments: