
Hi Roelof,
the problem is, you cannot pattern-match within guards. Guards take
predicates.
On your example: "last3 a" pattern-matches the first argument of last3
into a. You may now use a in all further statements. If, however, you
want to do pattern matching, it would look like this:
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.
Max
Am Sun, 09 Nov 2014 17:38:26 +0100
schrieb Roelof Wobben
Hello,
Im trying to find several answers to problem1 of the 99 haskell problems. Find the last item in a list.
Now im trying to find a guarded solution. So far I have this:
last3::[a]-> Maybe a; last3 a | [] = Nothing | ([a]) = Just a | (_:xs) = last3 xs
But I see this error messages :
src/Main.hs@10:8-10:10Not in scope: xs
How to solve this ?
Roelof
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe