SHOW:
|
|
- or go back to the newest paste.
| 1 | A2)a) | |
| 2 | ||
| 3 | mapList :: (Int -> Int) -> List -> List | |
| 4 | mapList _ [] = [] | |
| 5 | mapList f (x:xs) = f x : maplist f xs | |
| 6 | ||
| 7 | b) | |
| 8 | negateList :: List -> List | |
| 9 | neagteList xs = mapList (\x -> -x) x:xs | |
| 10 | ||
| 11 | c) | |
| 12 | foldList :: (Int -> a -> a) -> a -> List -> a | |
| 13 | foldList f c Nil = c | |
| 14 | - | foldList f c Cons( a n) = f a (foldList f c n) |
| 14 | + | foldList f c Cons( a n) = f a (foldList f c n) |
| 15 | ||
| 16 | d) | |
| 17 | sumList :: List -> Int | |
| 18 | sumList = foldList(\x:xs -> x + sumList(xs) |