Re: arity of type constructors

From: Xavier Leroy (Xavier.Leroy@inria.fr)
Date: Wed May 21 1997 - 20:46:49 MET DST


From: Xavier Leroy <Xavier.Leroy@inria.fr>
Message-Id: <199705211846.UAA01284@pauillac.inria.fr>
Subject: Re: arity of type constructors
In-Reply-To: <E0wU8yQ-0008Ks-00@heaton.cl.cam.ac.uk> from John Harrison at "May 21, 97 11:50:23 am"
To: John.Harrison@cl.cam.ac.uk (John Harrison)
Date: Wed, 21 May 1997 20:46:49 +0200 (MET DST)

>
> > Caml Light version 0.73
>
> #type triv = Triv of int*int;;
> Type triv defined.
> #let getpair = fun (Triv(p)) -> p;;
> getpair : triv -> int * int = <fun>
>
> Is this sort of definition safe? Perhaps one should use the following
> to ensure a pair is reconstructed:
>
> #let getpair = fun (Triv(a,b)) -> a,b;;

The Caml Light compiler will figure it out itself -- it emits code to
reconstruct the pair as in your second version of getpair.

The reason Objective Caml insists on constructors having an arity,
instead of generating correcting code as Caml Light, is that
Objective Caml's module calculus, and in particular functors, makes it
much harder to generate the right correcting code. That problem plagues all
implementations of Standard ML, and considerable ingenuity has been
expanded to handle it. I think it simply makes more sense to expose
the arity of constructors to the programmers.

- Xavier Leroy



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:11 MET