Skip to content

Instantly share code, notes, and snippets.

@motokiee
Created October 2, 2015 00:43
Show Gist options
  • Save motokiee/0d788fc29fa6f9dcb1c5 to your computer and use it in GitHub Desktop.
Save motokiee/0d788fc29fa6f9dcb1c5 to your computer and use it in GitHub Desktop.
けさのHaskellの勉強はここまで #CodePiece
replicate' :: Int -> a -> [a]
replicate' n x
| n <= 0 = []
| otherwise = x : (replicate' (n-1) x)
maximum' :: (Ord a) => [a] -> a
maximum' xs = case xs of [] -> error "maximum of empty list"
[x] -> x
(x:xs) -> max x (maximum' xs)
take' :: Int -> [a] -> [a]
take' n _
| n <= 0 = []
take' _ [] = []
take' n (x:xs) = x : take' (n-1) xs
reverse' :: [a] -> [a]
reverse' [] = []
reverse' (x:xs) = reverse' xs ++ [x]
repeat' :: a -> [a]
repeat' x = [x] ++ repeat' x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment