Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
arity of type constructors
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: arity of type constructors
>   >       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