caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: gava@univ-paris12.fr
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] (int * int) <> int*int ?
Date: Fri, 24 Feb 2006 09:01:16 +0900 (JST)	[thread overview]
Message-ID: <20060224.090116.89069794.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <00c201c638b1$b2b96860$1f570b50@mshome.net>

From: Frédéric Gava <gava@univ-paris12.fr>
> < For performance issues, is there a way to not have the rebuild
> > of the pair in
> > # type t = A of int*int | B of (int*int);;
> > # fun x -> match x with A (a,b) -> (a,b) | B a -> a;;
> >
> > ?
> Peraps this idea:
> if (all the time) A of (int*int) ==> A of int*int then in pattern mathching
> "A a" the "a" is directly built as a tuple from the tuple of the concrete
> type (just a little modification of the tag). Is it not a good idea ;-) ?

You can't do this, because values are shared: if you replace the A tag
by 0, you have really changed the original value for x, and subsequent
pattern-matching will be wrong.
Interestingly, it would be safe to just return x itself: when you
access a tuple you never look at its tag. However, this would still be
incorrect because of polymorphic equality: A(a,b) is not structurally
equal to 0(a,b) (assuming A is not the first tag.)

So there's no solution here.

By the way, the answer to your original question is that the syntax
for datatypes is wrong. A datatype does not take a tuple as argument,
but a fixed number of independent values. As somebody already pointed,
the revised syntax corrects this. The standard syntax is just a
consequence of history.
This unfortunate syntax has consequences down to polymorphic variants,
which otherwise could be represented more efficiently.

Jacques


  reply	other threads:[~2006-02-24  0:01 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-23 17:28 Frédéric Gava
2006-02-23 18:33 ` [Caml-list] " Eric Cooper
2006-02-23 19:03   ` Martin Jambon
2006-02-23 19:07   ` Frédéric Gava
2006-02-23 20:15     ` Brian Hurt
2006-02-23 21:30       ` Frédéric Gava
2006-02-23 21:57         ` Brian Hurt
2006-02-23 22:30           ` Frédéric Gava
2006-02-23 22:50             ` Brian Hurt
2006-02-23 23:07               ` Frédéric Gava
2006-02-24  8:38     ` Alessandro Baretta
2006-02-24 12:59     ` Damien Doligez
2006-02-23 18:33 ` Thomas Fischbacher
2006-02-23 18:56 ` David Brown
2006-02-23 19:24   ` Frédéric Gava
2006-02-23 19:37   ` Frédéric Gava
2006-02-23 19:45     ` Frédéric Gava
2006-02-24  0:01       ` Jacques Garrigue [this message]
2006-02-24  0:18         ` Lukasz Stafiniak
2006-02-24  2:17           ` Jacques Garrigue
2006-02-24 13:07             ` Alain Frisch
2006-02-25 17:42               ` Vincent Balat
2006-02-25 18:30                 ` Nicolas Pouillard
2006-02-25 19:09                   ` Richard Jones
2006-03-01 12:48                     ` Nicolas Pouillard
2006-02-25 23:17                   ` Christophe TROESTLER
2006-03-01 13:01                     ` Nicolas Pouillard
2006-02-27 11:14                   ` camlp4 renovation [was: [Caml-list] (int * int) <> int*int ?] Hendrik Tews
2006-02-24 13:39             ` [Caml-list] (int * int) <> int*int ? Nicolas Cannasse
2006-02-24 14:49               ` Frédéric Gava
2006-02-24  8:27   ` also for tagged records? [Was: Re: [Caml-list] (int * int) <> int*int ?] Sebastian Egner
2006-02-24 14:01     ` Thomas Fischbacher
2006-02-23 20:58 ` [Caml-list] (int * int) <> int*int ? Jon Harrop
2006-02-23 21:36   ` Frédéric Gava

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060224.090116.89069794.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@yquem.inria.fr \
    --cc=gava@univ-paris12.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).