[clean-list] Clean Book Part II Case studies

John W. Small jsmall@laser.net
Sat, 16 Mar 2002 13:20:24 -0500


This is a multi-part message in MIME format.

------=_NextPart_000_0013_01C1CCED.54FDF710
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,

The Clean book is excellent and I've been studying it in detail these =
past two
weeks.

    http://www.cs.kun.nl/~clean/Manuals/Clean_Book/clean_book.html

In Chapter 5 on parser combinators section 5.10 "Generalized =
Expressions"
I get an

    Overloading error (Parser.icl,286,gen]: internal overloading of =
"comprehension [line 298]" could not be solved


    // Generalized expression parser
    gen :: ([symbol] tree tree -> tree) [[symbol]] (Parser symbol tree) =
-> Parser symbol tree | =3D=3D symbol
    gen expression_constructor operators operand_parser
      =3D chainl operand_parser (choice [ token op <@ =
expression_constructor \\ op <- operators])
    //  =3D chainl operand_parser (choice alternatives)
    //  where alternatives =3D map (\op -> token op =
<@expression_constructor)  operators

If I try the map instead I get basically the same error

    Overloading error [Parser.icl,286,gen]: internal overloading of =
"lambda [line 290]" could not be solved.

It would seem that

    token op <@ expression_constructor

would be of type

    Parser symbol  (tree tree -> tree)

which is what is required by "choice"  and ultimately "chainl =
operand_parser ..."

I tried replacing the Parser type abbreviation with its actual =
specification, i.e. [symbol] -> ([symbol],...)
but that didn't help matters.  I don't believe "choice" has anything to =
do with it but not knowing much
about Clean or functional programming I've including its specification =
as I coded it below

    // Choice parser, i.e. from a list of alternatives
    choice :: [(Parser symbol tree)] -> Parser symbol tree
    choice [p]    =3D p
    choice [p:ps] =3D p <|> choice ps
    choice []     =3D abort "At least one alternative parser required in =
choice parser."

I'm using the Clean 2.0 on Windows 2000.  Has something changed in the =
type inferencing
system between 2.0 and the version of Clean that the book example was =
test upon?  I know
that can't be - what have I done wrong?

Thank you.

John





------=_NextPart_000_0013_01C1CCED.54FDF710
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.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>The Clean book is excellent and I've been studying =
it in=20
detail these past two</FONT></DIV>
<DIV><FONT size=3D2>weeks.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; <FONT =
face=3DArial><A=20
href=3D"http://www.cs.kun.nl/~clean/Manuals/Clean_Book/clean_book.html">h=
ttp://www.cs.kun.nl/~clean/Manuals/Clean_Book/clean_book.html</A></FONT><=
/FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>In Chapter 5 on parser combinators section 5.10 =
"Generalized=20
Expressions"</FONT></DIV>
<DIV><FONT size=3D2>I get an</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Overloading error=20
(Parser.icl,286,gen]: internal overloading of "comprehension [line 298]" =
could=20
not be solved</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial></FONT><FONT face=3DArial></FONT><FONT=20
face=3DArial></FONT><FONT face=3DArial></FONT><FONT =
face=3DArial></FONT><FONT=20
face=3DArial></FONT><FONT face=3DArial></FONT><BR>&nbsp;&nbsp;&nbsp; // =
Generalized=20
expression parser<BR>&nbsp;&nbsp;&nbsp; gen :: ([symbol] tree tree -&gt; =
tree)=20
[[symbol]] (Parser symbol tree) -&gt; Parser symbol tree | =3D=3D=20
symbol<BR>&nbsp;&nbsp;&nbsp; gen expression_constructor operators=20
operand_parser<BR>&nbsp;&nbsp;&nbsp; &nbsp; =3D chainl operand_parser =
(choice [=20
token op &lt;@ expression_constructor \\ op &lt;-=20
operators])<BR>&nbsp;&nbsp;&nbsp; //&nbsp; =3D chainl operand_parser =
(choice=20
alternatives)<BR>&nbsp;&nbsp;&nbsp; //&nbsp; where alternatives =3D map =
(\op -&gt;=20
token op &lt;@expression_constructor)&nbsp; operators</DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>If I try the map instead I get basically the =
same=20
error</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; Overloading error =
[Parser.icl,286,gen]:=20
internal overloading of "lambda [line 290]" could not be =
solved.</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>It would seem that</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; token op &lt;@=20
expression_constructor</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>would be of type</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; Parser symbol &nbsp;(tree =
tree -&gt;=20
tree)</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>which is what is required by "choice" &nbsp;and =
ultimately=20
"chainl operand_parser ..."</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>I tried replacing the Parser type abbreviation =
with its=20
actual specification, i.e. [symbol] -&gt; ([symbol],...)</FONT></DIV>
<DIV>but that didn't help matters.&nbsp; I don't believe "choice" has =
anything=20
to do with it but not knowing much</DIV>
<DIV>about Clean or functional programming I've including its =
specification as I=20
coded it below</DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>&nbsp;&nbsp;&nbsp; // Choice parser, i.e. from a =
list of=20
alternatives<BR>&nbsp;&nbsp;&nbsp; choice :: [(Parser symbol tree)] =
-&gt; Parser=20
symbol tree<BR>&nbsp;&nbsp;&nbsp; choice [p]&nbsp;&nbsp;&nbsp; =3D=20
p<BR>&nbsp;&nbsp;&nbsp; choice [p:ps] =3D p &lt;|&gt; choice=20
ps<BR>&nbsp;&nbsp;&nbsp; choice []&nbsp;&nbsp;&nbsp;&nbsp; =3D abort "At =
least one=20
alternative parser required in choice parser."</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial><FONT face=3DArial>I'm using the Clean 2.0 on =
Windows=20
2000.&nbsp; Has something changed in the type =
inferencing</FONT></FONT></DIV>
<DIV><FONT face=3DArial>system between 2.0 and the version of Clean that =
the book=20
example was test upon?&nbsp; I know</FONT></DIV>
<DIV>that can't be - what have I done wrong?</DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>Thank you.</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>John</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial></FONT><BR></DIV></FONT></FONT></BODY></HTML>

------=_NextPart_000_0013_01C1CCED.54FDF710--