Type classes question

Eugene Nonko enonko@windows.microsoft.com
Fri, 29 Aug 2003 13:03:09 -0700


This is a multi-part message in MIME format.

--------------InterScan_NT_MIME_Boundary
Content-Type: multipart/alternative;
	boundary="----_=_NextPart_001_01C36E68.D0D61133"

------_=_NextPart_001_01C36E68.D0D61133
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hello,

I am trying to define class Dual and few instances as follows:

=3D=3D=3D
class Dual a where
    dual :: a -> a

instance Dual Bool where
    dual =3D not

instance (Dual a, Dual b) =3D> Dual (a -> b) where
    dual f =3D dual . f . dual

instance Dual a =3D> Dual [a] where
    dual =3D reverse . map dual

instance Num a =3D> Dual a where
    dual =3D negate
=3D=3D=3D

For some reason Hugs does not lake the last definition saying 'ERROR
dual.hs:13 - syntax error in instance head (constructor expected)'. What
am I doing wrong?

-- Eugene

------_=_NextPart_001_01C36E68.D0D61133
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
6.5.6944.0">
<TITLE>Type classes question</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P><SPAN LANG=3D"en-us"><FONT SIZE=3D2 =
FACE=3D"Tahoma">Hello,</FONT></SPAN>
</P>

<P><SPAN LANG=3D"en-us"><FONT SIZE=3D2 FACE=3D"Tahoma">I am trying to =
define class Dual and few instances as follows:</FONT></SPAN><SPAN =
LANG=3D"ru"></SPAN>
</P>

<P><SPAN LANG=3D"en-us"><FONT SIZE=3D2 =
FACE=3D"Tahoma">=3D=3D=3D</FONT></SPAN><SPAN LANG=3D"ru"></SPAN>

<BR><SPAN LANG=3D"ru"><FONT SIZE=3D2 FACE=3D"Tahoma">class Dual a =
where</FONT></SPAN>

<BR><SPAN LANG=3D"ru"><FONT SIZE=3D2 FACE=3D"Tahoma">&nbsp;&nbsp;&nbsp; =
dual :: a -&gt; a</FONT></SPAN>
</P>

<P><SPAN LANG=3D"ru"><FONT SIZE=3D2 FACE=3D"Tahoma">instance Dual Bool =
where</FONT></SPAN>

<BR><SPAN LANG=3D"ru"><FONT SIZE=3D2 FACE=3D"Tahoma">&nbsp;&nbsp;&nbsp; =
dual =3D not</FONT></SPAN>
</P>

<P><SPAN LANG=3D"ru"><FONT SIZE=3D2 FACE=3D"Tahoma">instance (Dual a, =
Dual b) =3D&gt; Dual (a -&gt; b) where</FONT></SPAN>

<BR><SPAN LANG=3D"ru"><FONT SIZE=3D2 FACE=3D"Tahoma">&nbsp;&nbsp;&nbsp; =
dual f =3D dual . f . dual</FONT></SPAN>
</P>

<P><SPAN LANG=3D"ru"><FONT SIZE=3D2 FACE=3D"Tahoma">instance Dual a =
=3D&gt; Dual [a] where</FONT></SPAN>

<BR><SPAN LANG=3D"ru"><FONT SIZE=3D2 FACE=3D"Tahoma">&nbsp;&nbsp;&nbsp; =
dual =3D reverse . map dual</FONT></SPAN>
</P>

<P><SPAN LANG=3D"ru"><FONT SIZE=3D2 FACE=3D"Tahoma">instance Num a =
=3D&gt; Dual a where</FONT></SPAN>

<BR><SPAN LANG=3D"ru"><FONT SIZE=3D2 FACE=3D"Tahoma">&nbsp;&nbsp;&nbsp; =
dual =3D negate</FONT></SPAN>

<BR><SPAN LANG=3D"en-us"><FONT SIZE=3D2 =
FACE=3D"Tahoma">=3D=3D=3D</FONT></SPAN><SPAN LANG=3D"ru"></SPAN>
</P>

<P><SPAN LANG=3D"en-us"><FONT SIZE=3D2 FACE=3D"Tahoma">For some reason =
Hugs does not lake the last definition saying '</FONT></SPAN><SPAN =
LANG=3D"ru"><FONT SIZE=3D2 FACE=3D"Tahoma">ERROR dual.hs:13 - syntax =
error in instance head (constructor expected)</FONT></SPAN><SPAN =
LANG=3D"en-us"><FONT SIZE=3D2 FACE=3D"Tahoma">'. What am I doing =
wrong?</FONT></SPAN></P>

<P><SPAN LANG=3D"en-us"><FONT SIZE=3D2 FACE=3D"Tahoma">-- =
Eugene</FONT></SPAN><SPAN LANG=3D"ru"></SPAN>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C36E68.D0D61133--

--------------InterScan_NT_MIME_Boundary--