Created
March 15, 2016 20:09
-
-
Save ngscheurich/2d5689e97136a9693c51 to your computer and use it in GitHub Desktop.
Reimplementation of Haskell’s `head`, `tail`, `init`, and `last` functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- http://www.codewars.com/kata/54592a5052756d5c5d0009c3/train/haskell | |
module ListOps where | |
import Prelude hiding (head, tail, init, last) | |
head :: [a] -> a | |
head (x:_) = x | |
tail :: [a] -> [a] | |
tail (_:xs) = xs | |
init :: [a] -> [a] | |
init [_] = [] | |
init (x:xs) = x:init xs | |
last :: [a] -> a | |
last [x] = x | |
last (x:xs) = last xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment