Personal tools

99 questions/Solutions/1

From HaskellWiki

< 99 questions | Solutions(Difference between revisions)
Jump to: navigation, search
Line 9: Line 9:
   
 
myLast'' = head . reverse
 
myLast'' = head . reverse
 
myLast''' xs = xs !! (length xs - 1)
 
 
</haskell>
 
</haskell>
   

Revision as of 10:28, 29 March 2011

(*) Find the last element of a list.

myLast :: [a] -> a
myLast [x] = x
myLast (_:xs) = myLast xs
 
myLast' = foldr1 (const id)
 
myLast'' = head . reverse
The
Prelude
also provides the function
last
.