-------------------- anonymous function (\)
-- greaterThan100 [1,9,349,6,907,98,105] == [349,907,105]
-- form 1
gt100 :: Integer -> Bool
gt100 x = x > 100
greater1Than100 :: [Integer] -> [Integer]
greater1Than100 xs = filter (gt100) xs
-- form 2
greater2Than100 :: [Integer] -> [Integer]
greater2Than100 xs = filter (\x -> x > 100) xs
-- form 3
greater3Than100 :: [Integer] -> [Integer]
greater3Than100 xs = filter (>100) xs
--print ((>100) 102, (100>) 102, map (*6) [1..5])
-------------------- anonymous function (.)
-- form 1
myTest :: [Integer] -> Bool
myTest xs = even (length (greater3Than100 xs))
-- form 2
my2Test :: [Integer] -> Bool
my2Test = even . length . greater3Than100
--print (myTest [1,9,349,6,907,98,105])
-- what is (.)? -> try :t (.)
-- (b -> c) -> (a -> b) -> (a -> c) ?
-- foo f g = ...
-- foo f g = \x -> ...
-- foo f g = \x -> f (g x)
--------------------------- Curring
f :: (Int,Int) -> Int
f (x,y) = 2*x + y
--- is same as
f2 :: Int -> Int -> Int
f2 x y = 2*x + y
--- and a builtin function called Curring (schÃ¶nfinkel) and Uncurring
-- ==============point-free or wholemeal ============================
-- we learn all of this to convert the following form
foobar :: [Integer] -> Integer
foobar [] = 0
foobar (x:xs)
| x > 3 = (7*x + 2) + foobar xs
| otherwise = foobar xs
-- to this form
foo2bar :: [Integer] -> Integer
foo2bar = sum . map (\x -> 7*x + 2) . filter (>3)