Skip to content

Instantly share code, notes, and snippets.

@lipemorais
Created December 14, 2016 17:53
Show Gist options
  • Save lipemorais/9501e180086113115e0d15a434ffcef6 to your computer and use it in GitHub Desktop.
Save lipemorais/9501e180086113115e0d15a434ffcef6 to your computer and use it in GitHub Desktop.
myLast :: Eq a => [a] -> a
myLast (x:xs)
| xs == [] = x
| otherwise = myLast xs
myLast' :: Eq a => [a] -> a
myLast' (x:y:xs)
| xs == [] = x
| otherwise = myLast' (y:xs)
elementAt :: (Eq b, Num b) => [a] -> b -> a
elementAt list 1 = head list
elementAt (primeiro:list) index = elementAt list ((-) index 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment