-
Notifications
You must be signed in to change notification settings - Fork 0
/
anonymousfunctions.hs
52 lines (37 loc) · 1.21 KB
/
anonymousfunctions.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
greaterThan100 :: [Integer] -> [Integer]
greaterThan100 list = filter grt list
grt:: Integer -> Bool
grt int = int>100
-- using anonymous function
greaterThan100' :: [Integer] -> [Integer]
greaterThan100' list = filter (\x-> x>100) list
---- multiply three numbers
mul3 :: Integer->Integer->Integer->Integer
mul3 x y z = x*y*z
--- Function composition
foo :: (b->c)-> (a->b)-> (a->c)
foo f g = \x -> f(g x)
-- type of f = b -> C
-- type of g = a-> b
-- type of x = a
-- to get the output (a->c) we can move from a->b> c
howManyNumbers ::[Integer]-> Int
howManyNumbers list = length (greaterThan100 list)
howManyNumbers' :: [Integer] -> Int
howManyNumbers' = length.greaterThan100
howManyNumbersMore5 :: [Integer] ->Bool
howManyNumbersMore5 = (>5).length. greaterThan100
--computation ::[Int] -> Int
--computation [] = 0
--composition (x:xs)
-- | x>3 = 7*x+2 + foobar xs
-- |otherwise = foobar xs
computation' :: [Int] -> Int
computation' = sum.map (\x->7*x+2).filter (>3)
curry' :: ((a->b)->c)-> a->b->c
curry' = undefined
uncurry' = (a->b->c) -> (a,b)->c
uncurry'= undefined
fold:: b-> (a->b->b)->[a]-> b
fold z f [] = z
fold z f (x:xs) = f x ( fold z f xs)