Re: arity of type constructors

From: John Harrison (John.Harrison@cl.cam.ac.uk)
Date: Wed May 21 1997 - 12:50:23 MET DST


To: caml-list@inria.fr
Subject: Re: arity of type constructors
Date: Wed, 21 May 1997 11:50:23 +0100
From: John Harrison <John.Harrison@cl.cam.ac.uk>
Message-Id: <E0wU8yQ-0008Ks-00@heaton.cl.cam.ac.uk>

David Monniaux writes:

| If you declare type t = T of int*int, it declares a type t whose only
| constructor takes two parameters, of respective types int and int, not a
| constructor that takes one paramete of type int*int. Thus it can't be
| applied to a pair.
|
| That is reflected in the way memory objects are handled. A constructor
| that takes a pair as an argument will have the following layout:
|
| T -> pair [ int
| [ int
|
| if it has two arguments, the layout is the following:
|
| T [ int
| [ int
|
| Using a pair adds one level of indirection.

In that case, what happens during pattern-matching? For example:

> 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;;

John.



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