Browse thread
[Caml-list] Constructors as functions and tuples in constructors
[
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: | Michal Moskal <malekith@p...> |
| Subject: | Re: [Caml-list] Constructors as functions and tuples in constructors |
On Wed, Oct 08, 2003 at 07:57:03PM +0400, Serge wrote:
>
> Gentlemen!
Well, maybe there are some ladies here? :-)
[...]
> Second, it would also be nice not to have "the concept of constructor
> arity", and treat the code below as correct:
>
> type t = A of int * int
> let _ =
> match A (17, 0) with
> A z -> match z with (x, y) -> ()
Just need to use () after "of", like this:
# type t = A of (int * int);;
type t = A of (int * int)
# let _ = match A (17, 0) with A z -> z;;
- : int * int = (17, 0)
#
However constructing A of int * int takes one allocation (it's
<tag_of_a> <int> <int>), while A of (int * int) -- two (it's <tag_of_a>
<ptr_to_int_int>). Referencing it also takes one indirection more.
--
: Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv
: When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners