Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Constructors as functions and tuples in constructors
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Andreas Rossberg <rossberg@p...>
Subject: Re: [Caml-list] Constructors as functions and tuples in constructors
Dan Grossman wrote:
> 
>> 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) -> ()
> 
> Works with type t = A of (int * int).  You put the parens in.  So the 
> choice is yours.  The advantage of leaving them out is usually performance.

That is not true. It would be quite trivial for the compiler to translate

   A z -> e

into the equivalent of

   A(z1,z2) -> let z = (z1,z2) in e

without affecting performance of other programs in any way. Likewise,

   A z

could be transformed into

   let (z1,z2) = z in A(z1,z2)

instead of rejecting it. OTOH, your workaround certainly decreases 
performance for type t, as other pointed out.

-- 
Andreas Rossberg, rossberg@ps.uni-sb.de

"Computer games don't affect kids; I mean if Pac Man affected us
  as kids, we would all be running around in darkened rooms, munching
  magic pills, and listening to repetitive electronic music."
  - Kristian Wilson, Nintendo Inc.

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