Skip to content

Commit

Permalink
Added exercise0 from reasoning about programs lesson
Browse files Browse the repository at this point in the history
  • Loading branch information
PotHix committed Dec 30, 2015
1 parent 88d66d7 commit 2bcef77
Showing 1 changed file with 24 additions and 0 deletions.
@@ -0,0 +1,24 @@
last :: [a] -> a
last [x] = x
last (_ : xs) = last xs

foldr :: (a -> b -> b) -> b -> [a] -> b
foldr _ v [] = v
foldr f v (x : xs) = f x (foldr f v xs)

init :: [a] -> [a]
init [_] = []
init (x : xs) = x : init xs

drop :: Int -> [a] -> [a]
drop 0 xs = xs
drop n [] = []
drop n (_ : xs) = drop (n - 1) xs

(++) :: [a] -> [a] -> [a]
[] ++ ys = ys
(x : xs) ++ ys = x : (xs ++ ys)

foldl :: (a -> b -> a) -> a -> [b] -> a
foldl _ v [] = v
foldl f v (x : xs) = foldl f (f v x) xs

0 comments on commit 2bcef77

Please sign in to comment.