# 99 questions/Solutions/1

### From HaskellWiki

< 99 questions | Solutions(Difference between revisions)

m |
|||

Line 15: | Line 15: | ||

myLast''' = head . reverse | myLast''' = head . reverse | ||

+ | |||

+ | myLast'''' = foldl1 (curry snd) | ||

</haskell> | </haskell> | ||

The <hask>Prelude</hask> also provides the function <hask>last</hask>. | The <hask>Prelude</hask> also provides the function <hask>last</hask>. |

## Revision as of 00:21, 26 July 2012

(*) Find the last element of a list.

myLast :: [a] -> a myLast [x] = x myLast (_:xs) = myLast xs myLast' = foldr1 (const id) -- Prelude> const 1 2 -- 1 -- Prelude> (flip const) 1 2 -- 2 myLast'' = foldr1 (flip const) myLast''' = head . reverse myLast'''' = foldl1 (curry snd)

Prelude

last