Professional Documents
Culture Documents
a)
a) e1 :: [Bool]
b) e2 :: (Int, Int, Int)
c) e3 x = (x,x,x)
d) e4 xs ys = xs or ys or xs ++ ys
e) e5 = \x -> (\y -> x+y)
b)
c)
sum [] = 0
length [] = 0
reverse [] = []
map f [] = []
replicate 0 x = []
d)
fac 3
= 3 * fac 2
= 3 * (2 * fac 1)
= 3 * (2 * (1 * fac 0))
= 3 * ( 2 * (1 *1))
=3 * (2 *1)
=3*2=6
Question 2:
Insert x [] = [x]
x : y : ys
else
Y : insert x ys
b)
insert 3 [1,2,4,5]
= 1 : insert 3 [2,4,5]
= 1 : 2 : insert 3 [4,5]
= 1 : 2 : 3 : [4,5]
= [1,2,3,4,5]
c)
isort [] = []
d)
isort [3,2,1]
=insert 3 [1,2]
=insert [1,2,3]
qsort [] = []
qsort (x:xs) =
++ [x] ++
g)
qsort [3,2,4,1,5]
[1] [] [] [5]