Overloading and Literal Numerics

Jon Fairbairn Jon.Fairbairn@cl.cam.ac.uk
Thu, 27 Jun 2002 15:49:14 +0100


> Alain Cremieux wrote:
> I am trying to build a functional firewall generator. The first part
> describes the available protections (kernel, anti-address spoofing, etc=
=2E).
> The second desribes every protocol, and the necessary rules if the
> corresponding service is enabled (e.g. open the http port...). In the t=
hird
> one, the user will choose the services he wants to use/open and the sta=
tic
> parameters (for instance the squid port number).
> I wanted the user part to be "user-friendly", even if it is an Haskell
> program. So the commands
> definePort "squidPort" 3128
> Seemed more logical than
> definePort "squidPort" "3128"
> =

> The problem is that the numeric literal 3128 is considered as being a m=
ember
> of Num class, and not as beeing an Int.
> So I can't write a unique function which accepts 1) the string "3128" 2=
) the
> literal numeric 3128   3) the string "3128:3129"(if the user wants to g=
ive a
> port range, for instance)

I understand the problem, but I still don't see why you want
strings here. [Int] would do. They'd just have to type
[3218..3130] for a range of port numbers, and you can define
ordinary variables:

   type Port =3D [Int]
   http:: Port
   http =3D [80]

You'd have to have them type

definePort "squidPort" [3128]

and that allows giving a range of ports where only one port
is required, but at least they are going to be constrained
to be numbers. With this, portRange [3128.3129] will give a
compile time error, where portRange "3128.3129" would have
to be a run-time error.

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