1 Problem 1
(*) Find the last element of a list.
(Note that the Lisp transcription of this problem is incorrect.)
Example in Haskell
Prelude> myLast [1,2,3,4] 4 Prelude> myLast ['x','y','z'] 'z'
run::[a]->a
run [x]=x
run (_:xs) = run xs
run = foldl (const id)
对于上述的代码,有如下的解释
const id True 2
= (const id True) 2
= id 2
= 2
如果要保留第一个,可以用如下的代码
foldl1 const [1,2,3,4]