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>&nbsp;</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>&nbsp;</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>&nbsp;</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]-&gt;[(String,[String])])}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>instance Monad AParser where<BR>&nbsp; =
return=20
v&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =3D AP (\inp -&gt;=20
[(v,inp)])<BR>&nbsp; (AP p) &gt;&gt;=3D f&nbsp;&nbsp;&nbsp; =3D AP (\inp =
-&gt;=20
concat [ apapply (f v) inp1 | (v,inp1) &lt;- p inp])</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial=20
size=3D2>----------------------------------------------------------------=
-----------------------------------</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>error:</DIV>
<DIV>
<DIV><FONT face=3DArial=20
size=3D2>----------------------------------------------------------------=
-----------------------------------</FONT></DIV>
<DIV>&nbsp;&nbsp;&nbsp; Inferred type is less polymorphic than=20
expected<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Quantified type =
variable=20
`b' is unified with another quantified type variable =
`a'<BR>&nbsp;&nbsp;&nbsp;=20
When trying to generalise the type inferred for=20
`&gt;&gt;=3D'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Signature=20
type:&nbsp;&nbsp;&nbsp;&nbsp; forall a1=20
b1.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;=20
AParser a1 -&gt; (a1 -&gt; AParser b1) -&gt; AParser=20
b1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Type to generalise: =
forall a1=20
b1.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;=20
AParser a1 -&gt; (a1 -&gt; AParser b1) -&gt; AParser =
b1<BR>&nbsp;&nbsp;&nbsp; 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>&nbsp;</DIV>
<DIV>But when I create the&nbsp;type synonym</DIV>
<DIV>type Stack =3D [String]</DIV>
<DIV>data AParser String =3D AP {apapply::(Stack -&gt; =
[(String,Stack)])}</DIV>
<DIV>&nbsp;</DIV>
<DIV>and use Stack instead of [String], GHC does not complain???</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks.</DIV></DIV>
<DIV>Mansour.</DIV></DIV></FONT></DIV></BODY></HTML>

------=_NextPart_000_001D_01C2E5EE.C0996250--