
9 Nov
2014
9 Nov
'14
12:11 p.m.
On Mon, Nov 10, 2014 at 12:04 AM, Max Voit
last3::[a]-> Maybe a; last3 [] = Nothing last3 ([a]) = Just a last3 (_:xs) = last3 xs
Notice that the last case will never be executed, as the matching is complete with the first two case.
Lists are tricky because of the special syntax. The first case is [] or Nil, the second is [a] which is equivalent to (a:[]). Hence there's a remaining case of a Cons cell (:) that's NOT followed by Nil ([]), which is the third case. -- Kim-Ee