> 10
> 5 + 3 + 4
> 9 - 1
> 6 / 2
> 2 * 3 + 4 * 6
> 7 < 9
> 3 <= 5 && 5 <= 3
> let a = 3 in a + 1
> let a = 1 in let b = a + 1 in a + b + a * b
> a
> let square n = n * n in square 4
> let fac n = if n == 0 then 1 else n * fac (n-1) in fac 5
Examples: > same-values == equal 3 1
True
> same-values < > 2 3
False
> same-values + * 2 2
True
fac n = fac_help n 1
where fac_help 0 acc = acc
fac_help n acc = silnia_help (n - 1) (n * acc)
Here the variable acc of function fac_help is called an accumulator.> pairing [1,2,3] [a,b,c] [(1,a),(2,b),(3,c)]g) split x l splitting l into two lists l1 i l2, where l1 contains the elements smaller than x and l2 the elements greater than x.
> map2 (+) [1,2,3] [8,9,10] [9,11,13]b) Please define a function filter p l, whose value is the list of all elements of l fulfilling the one-argument predicate p.
>take_while odd [1,3,5,6,7] [1,3,5] > take_while (\x -> x > 0) [1,4,2,-1,5] [1,4,2]d) Please define a function groups l that will append consecutive identical elements from list l. Example:
> compress [1,1,3,3,3,3,2,2,2,2,2,7,7,2,2] [[1,1],[3,3,3,3],[2,2,2,2,2],[7,7],[2,2]]
> iter square 2 3 81 > let f = iter square 2 in f 5 625 > iter square 0 7 7
angle (+c (make-rectangular -1 3) (make-polar 2 -2))is evaluated.
a) map square [1,2,3] b) map square ['a,'b,'c] c) \x -> 2 * x d) \f -> f 3 e) \f x -> f (f x) f) (\f x -> f (f x)) square g) \x -> x x h) f 7 (g 'a)You can use {} |- map :: (a -> b) -> [a] -> [b] and {} |- square :: Int -> Int
a) f [] = [] f (x:xs) = (square x) : (f xs) b) append [] l = l append (x:xs) l = x : (append xs l) c) map f [] = [] map f (x:xs) = (f x) : (map f xs) d) sum f [] = 0 sum f (x:xs) = (f x) + (f xs) e) member x [] = False member x (y:ys) = (x == y) || (member x ys)
sum f x y = (f x) + (f y)Why does the expression sum length [1,2] ['a','b'] give a type error?
data BinTree a = Leaf a | Node a (BinTree a) (BinTree a)Please define the following functions.