Prob with numeric values

Martin Norbäck d95mback@dtek.chalmers.se
23 May 2002 15:46:08 +0200


--=-0vgXLGZfLD2s83Z5shvM
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

tor 2002-05-23 klockan 15.38 skrev Jos Mistiaen:
> Hello,
>=20
> I m having some difficulties with the following thing:
>=20
> I've made a class which looks somehow like this:
> class A a where
>    inc::a->a
>    ....
>=20
> now, when I want to make a instance of it with type Int and define the
> function inc like this:
>=20
> instance A Int where
>      inc a =3D a + 1
>=20
> I can't make a call to it when I enter the folowing
>=20
> inc 5
>=20
> (When I type inc 5::Int it does the job perfectly, because I explicitly s=
ay=20
> 5 is an Integer, but how can I tell the program 5 is an Int?????ithout=20
> saying it explicitly in the prompt)

Because 5 does not have type Int, it has type Num a =3D> a which means
that 5 can have any numeric type.

Since + works for any numeric type, you can make your instance more
general (so that it works for any numeric type, including Int)

instance Num a =3D> A a where
  inc a =3D a + 1

Regards,

	Martin

--=20
Martin Norb=E4ck          d95mback@dtek.chalmers.se             =20
Kapplandsgatan 40       +46 (0)708 26 33 60                   =20
S-414 78  G=D6TEBORG      http://www.dtek.chalmers.se/~d95mback/
SWEDEN                  OpenPGP ID: 3FA8580B

--=-0vgXLGZfLD2s83Z5shvM
Content-Type: application/pgp-signature; name=signature.asc

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: För information se http://www.gnupg.org/

iD8DBQA87PKgkXyAGj+oWAsRAqH6AJ9avn3V4qVQY+j69uj9nG9TLE3f1wCeKPfW
hTOSZ82no+a4uqn71xf8JWk=
=Y3h1
-----END PGP SIGNATURE-----

--=-0vgXLGZfLD2s83Z5shvM--