fromInteger

Saswat Anand iscp9157@nus.edu.sg
Fri, 1 Jun 2001 15:25:24 -0700


This is a multi-part message in MIME format.

------=_NextPart_000_002E_01C0EAAF.1478A080
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,
  I can't understand how the arithmatic operators like (+),(-) are =
defined and fromInteger works in that context.

Type Fun a =3D Int -> a

fun :: Fun Int
fun =3D (+1)

instance (Num a) =3D> Num (Fun a) where
 .........

(fun + 2) 10 and (2 + fun) 10 works fine. But how does it know it has to =
use fromInteger?

But If I want these,
  (Just 2 + fun) 10 and (fun + Just 2) 10
to work, then is there a way to tell which conversion function to use?

Thanks,
Saswat




------=_NextPart_000_002E_01C0EAAF.1478A080
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 content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,<BR>&nbsp; I can't understand how =
the arithmatic=20
operators like (+),(-) are defined and fromInteger works in that=20
context.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Type Fun a =3D Int -&gt; a</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>fun :: Fun Int<BR>fun =3D =
(+1)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>instance (Num a) =3D&gt; Num (Fun a)=20
where<BR>&nbsp;.........</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>(fun + 2) 10 and (2 + fun) 10 works =
fine. But how=20
does it know it has to use fromInteger?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>But If I want these,<BR>&nbsp; (Just 2 =
+ fun) 10=20
and (fun + Just 2) 10<BR>to work, then is there a way to tell which =
conversion=20
function to use?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,<BR>Saswat</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><BR></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_002E_01C0EAAF.1478A080--