Overloading and Literal Numerics

Jon Fairbairn Jon.Fairbairn@cl.cam.ac.uk
Thu, 27 Jun 2002 10:46:50 +0100


> Hi,
> I am trying to create an overloaded function "=E0 la Java" to be able t=
o
> call it either with a string or a number.
> Ex :
> definePort "http"
> definePort 80
> but I have problem with restrictions in Haskell's type system

> Is there a better solution ?

If we knew /why/ you wanted to do this we might be able to
help.  I can't see why you want to allow Strings, which have
far too wide a range of values, as arguments to something
that takes a port designator as an argument.

data Port =3D Tcpmux | Nbp | Echo_ddp | Rje | Zip | Echo_tcp | ...
             deriving Enum, ...

instance Num Port where ...

would seem like a better way to me.

  J=F3n

-- =

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!)