GHC Error Message.
Mansour Al-Mutairi
almutaim@hotmail.com
Sun, 9 Mar 2003 03:48:31 -0800
This is a multi-part message in MIME format.
------=_NextPart_000_001D_01C2E5EE.C0996250
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi,
Could someone please explain to me why the following error message =
happen:
When I load the following code into GHC I get an error message:
code:
-------------------------------------------------------------------------=
--------------------------
data AParser String =3D AP {apapply::([String]->[(String,[String])])}
instance Monad AParser where
return v =3D AP (\inp -> [(v,inp)])
(AP p) >>=3D f =3D AP (\inp -> concat [ apapply (f v) inp1 | =
(v,inp1) <- p inp])
-------------------------------------------------------------------------=
--------------------------
error:
-------------------------------------------------------------------------=
--------------------------
Inferred type is less polymorphic than expected
Quantified type variable `b' is unified with another quantified =
type variable `a'
When trying to generalise the type inferred for `>>=3D'
Signature type: forall a1 b1.
AParser a1 -> (a1 -> AParser b1) -> AParser =
b1
Type to generalise: forall a1 b1.
AParser a1 -> (a1 -> AParser b1) -> AParser =
b1
In the instance declaration for `Monad AParser'
Failed, modules loaded: none.
-------------------------------------------------------------------------=
--------------------------
But when I create the type synonym
type Stack =3D [String]
data AParser String =3D AP {apapply::(Stack -> [(String,Stack)])}
and use Stack instead of [String], GHC does not complain???
Thanks.
Mansour.
------=_NextPart_000_001D_01C2E5EE.C0996250
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2722.900" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Could someone please explain to me why =
the=20
following error message happen:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>When I load the following code into GHC =
I get an=20
error message:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>code:</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>----------------------------------------------------------------=
-----------------------------------</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>data AParser String =3D AP=20
{apapply::([String]->[(String,[String])])}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>instance Monad AParser where<BR> =
return=20
v =3D AP (\inp ->=20
[(v,inp)])<BR> (AP p) >>=3D f =3D AP (\inp =
->=20
concat [ apapply (f v) inp1 | (v,inp1) <- p inp])</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial=20
size=3D2>----------------------------------------------------------------=
-----------------------------------</FONT></DIV>
<DIV> </DIV>
<DIV>error:</DIV>
<DIV>
<DIV><FONT face=3DArial=20
size=3D2>----------------------------------------------------------------=
-----------------------------------</FONT></DIV>
<DIV> Inferred type is less polymorphic than=20
expected<BR> Quantified type =
variable=20
`b' is unified with another quantified type variable =
`a'<BR> =20
When trying to generalise the type inferred for=20
`>>=3D'<BR> Signature=20
type: forall a1=20
b1.<BR> =
&=
nbsp; =20
AParser a1 -> (a1 -> AParser b1) -> AParser=20
b1<BR> Type to generalise: =
forall a1=20
b1.<BR> =
&=
nbsp; =20
AParser a1 -> (a1 -> AParser b1) -> AParser =
b1<BR> In=20
the instance declaration for `Monad AParser'<BR>Failed, modules loaded:=20
none.</DIV>
<DIV>
<DIV><FONT face=3DArial=20
size=3D2>----------------------------------------------------------------=
-----------------------------------</FONT></DIV>
<DIV> </DIV>
<DIV>But when I create the type synonym</DIV>
<DIV>type Stack =3D [String]</DIV>
<DIV>data AParser String =3D AP {apapply::(Stack -> =
[(String,Stack)])}</DIV>
<DIV> </DIV>
<DIV>and use Stack instead of [String], GHC does not complain???</DIV>
<DIV> </DIV>
<DIV>Thanks.</DIV></DIV>
<DIV>Mansour.</DIV></DIV></FONT></DIV></BODY></HTML>
------=_NextPart_000_001D_01C2E5EE.C0996250--