Skip to content

Instantly share code, notes, and snippets.

@qoelet
Created July 31, 2013 03:13
Show Gist options
  • Save qoelet/6119005 to your computer and use it in GitHub Desktop.
Save qoelet/6119005 to your computer and use it in GitHub Desktop.
two definitions of 'init'
-- file: myInit.hs
-- 2 ways to define init function (removes last element from a non empty list)
myInitOne :: [a] -> [a]
myInitOne [x] = []
myInitOne (x:xs) = [x] ++ myInitOne xs
myInitTwo :: [a] -> [a]
myInitTwo x = take (length x - 1) x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment