Skip to content

Instantly share code, notes, and snippets.

@ngscheurich
Created March 15, 2016 20:09
Show Gist options
  • Save ngscheurich/2d5689e97136a9693c51 to your computer and use it in GitHub Desktop.
Save ngscheurich/2d5689e97136a9693c51 to your computer and use it in GitHub Desktop.
Reimplementation of Haskell’s `head`, `tail`, `init`, and `last` functions
-- 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