[Haskell-cafe] xs not in scope

Max Voit max.voit+mlhc at with-eyes.net
Sun Nov 9 17:04:40 UTC 2014


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 <r.wobben at home.nl>:

> 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 at 10:8-10:10Not in scope: xs
> 
> How to solve this ?
> 
> Roelof
> 
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list