Skip to content

Instantly share code, notes, and snippets.

@ignacioiglesias
Created September 17, 2012 16:24
Show Gist options
  • Save ignacioiglesias/3738301 to your computer and use it in GitHub Desktop.
Save ignacioiglesias/3738301 to your computer and use it in GitHub Desktop.
Find the last element of a list
module Main where
myLength :: [x] -> Int
myLength x =
foldr (\x y -> y + 1) 0 x
myLast :: [x] -> x
myLast x =
x !! ((myLength x) - 1)
main =
print (myLast [1, 2, 3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment