Browse thread
arity of type constructors
-
Christian Lindig
-
David Monniaux
- John Harrison
- Michel Quercia
-
David Monniaux
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | John Harrison <John.Harrison@c...> |
| Subject: | Re: arity of type constructors |
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.