[Haskell-cafe] xs not in scope

Kim-Ee Yeoh ky3 at atamo.com
Sun Nov 9 17:11:41 UTC 2014


On Mon, Nov 10, 2014 at 12:04 AM, Max Voit <max.voit+mlhc at with-eyes.net>
wrote:

> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20141110/5a562e2e/attachment.html>


More information about the Haskell-Cafe mailing list