type equivalency

Jon Fairbairn Jon.Fairbairn@cl.cam.ac.uk
Wed, 05 Jun 2002 22:39:37 +0100


> For example all functions with Int -> Int are type equivalent
> However,
> =

> data D a b =3D MkD a b

All objects D Int Int are type equivalent.  I'm not sure what
your question means, otherwise.

If you define =


data Function a b =3D F (a -> b)

apply:: Function a b -> a -> b
apply (F f) a =3D f a

you add an extra level of constructor, but you can still use
anything of type Function Int Int where Function Int Int is
required:

square:: Function Int Int
square =3D F (\ a -> a*a)

sqare_root:: Function Int Int
square_root =3D F (\ a -> round (sqrt (fromIntegral a)))

E&OE -- it's about my bedtime.


-- =

J=F3n Fairbairn                                 Jon.Fairbairn@cl.cam.ac.u=
k
31 Chalmers Road                                         jf@cl.cam.ac.uk
Cambridge CB1 3SZ            +44 1223 570179 (after 14:00 only, please!)