














Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!















fac :: Int ® Int fac n = product [1..n]
fac 0 = 1 fac n = n * fac (n-1)
fac 3 3 * fac 2
3 * (2 * fac 1)
3 * (2 * (1 * fac 0))
product :: Num a Þ [a] ® a product [] = 1 product (n:ns) = n * product ns
length :: [a] ® Int length [] = 0 length (_:xs) = 1 + length xs
length [1,2,3] 1 + length [2,3]
1 + (1 + length [3])
1 + (1 + (1 + length []))
reverse [1,2,3] reverse [2,3] ++ [1]
(reverse [3] ++ [2]) ++ [1]
((reverse [] ++ [3]) ++ [2]) ++ [1]
zip :: [a] ® [b] ® [(a,b)] zip [] _ = [] zip _ [] = [] zip (x:xs) (y:ys) = (x,y) : zip xs ys
qsort :: Ord a Þ [a] ® [a] qsort [] = [] qsort (x:xs) = qsort smaller ++ [x] ++ qsort larger where smaller = [a | a ¬ xs, a £ x] larger = [b | b ¬ xs, b > x]
and :: [Bool] ® Bool
concat :: [[a]] ® [a]
(!!) :: [a] ® Int ® a
elem :: Eq a Þ a ® [a] ® Bool
replicate :: Int ® a ® [a]