[Haskell-cafe] Help a Newbie

Philippa Cowderoy flippa at flippac.org
Fri Feb 20 22:05:32 EST 2004

On Fri, 20 Feb 2004, Matthew Morvant wrote:

> I am trying (and have been for quite some time) to repair a broken Haskel=
> script.=A0 I keep getting stuck on =93Last generator in do {...} must be =
> expression=94.=A0 I am betting that this is not uncommon.=A0 Can someone =
> help me understand?
> code5 :: Parser
> code5 =3D do
>          dd <- code3
>          do ddd <- code3
>          do dddd <- code3
>          return "ce"

The author appears to want this (braces and semicolons included for

code5 =3D do {
            dd <- code3;
            ddd <- code3;
            dddd <- code3;
            return "ce"

which will assign the results of code3 3 times in succession to dd, ddd,
and ddd before returning "ce". Of course, you /could/ just write that as:

do {code3; code 3; code 3; return "ce"}

Unless I misunderstand the intent here?

> code4 :: Parser
> code4 =3D do
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 dd <-=
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 do =
dde <- code3
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 digit
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ddd <- many (do digit)
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 q <- code5
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return (q : "ss")

Attempting to grok this suggests I might. Is code3 supposed to take a
parser as a parameter?

flippa at flippac.org

More information about the Haskell-Cafe mailing list