caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Brian Hurt <bhurt@spnz.org>
Cc: Lukasz Stafiniak <lukstafi@gmail.com>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Feature request : Tuples vs. records
Date: Sun, 25 Feb 2007 05:14:10 +1100	[thread overview]
Message-ID: <1172340850.5345.39.camel@rosella.wigram> (raw)
In-Reply-To: <Pine.LNX.4.64.0702241043560.19734@localhost>

On Sat, 2007-02-24 at 10:50 -0500, Brian Hurt wrote:
> 
> On Sat, 24 Feb 2007, Lukasz Stafiniak wrote:
> 
> > I have this idea... We could have row polymorphism in tuples, without
> > any impact on performance! Instead of insisting that ('a * 'b) means
> > exactly two elements, we could have (> 'a * 'b) at least two elements.
> > Any projections or pattern matching fetches the tuple fields without
> > problems: it doesn't need to care that there are more than it needs.
> >
> > Say you realize that you need to return another value from a function
> > (which already returns a tuple): you would only modify the function
> > and not its uses.
> 
> Not being able to do this is one of the reasons I *like* Ocaml.
> 
> Consider the case where the calling location is:
>  	let a, b = foo ... in
>  	...
> 
> Now you change foo to return 3 tuples instead of just 2.  What happens?
> 
> If you say "The third element quietly gets dropped", I'll respond with "if 
> I wanted that behavior, I'd be coding in Perl."

I think you're taking his idea too literally: consider instead
an explicit syntax which allows tuples to be pattern matched
like lists. Felix can actually do this:

/////////////////////////////////////////
#import <flx.flxh>

typedef fun xcur(t:TYPE):TYPE => typematch t with
  | ?a -> ?b => a * xcur b
  | _ => t
endmatch;

var x : xcur (int->long->double) = (1,(2L,3.0));

match x with
| ?a,(?b,?c) => { 
  print a; print " "; 
  print b; print " "; 
  print c; endl;
}
endmatch;
//////////////////////////////////////////

The thing to note here is that we have a generic pattern match
which can fold along the components of a function type
using recursion. (This is an example of my version of Jay
pattern calculus).

But you cannot recurse over a tuple like this because it
isn't built up inductively from a binary operator.

We can adapt Lukasz suggestion to make it possible,
by for example the syntax:

  head, tail ...

or some such, which treats a tuple like a list. Of course
such a construction should be *explicit*.

Similarly, a version of this could work for arrays: it would
be data polymorphic but not generic (since all array elements
have the same type).


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


  reply	other threads:[~2007-02-24 18:14 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-22 15:34 Frederic GAVA
2007-02-22 16:16 ` David Teller
2007-02-23  1:39   ` Jacques Garrigue
2007-02-23 13:34     ` Richard Jones
2007-02-23 13:43       ` Till Varoquaux
2007-02-23 14:14         ` Nicolas Pouillard
2007-02-23  1:45   ` Jon Harrop
2007-02-23 16:32     ` Lukasz Stafiniak
2007-02-24 13:43       ` Lukasz Stafiniak
2007-02-24 15:50         ` Brian Hurt
2007-02-24 18:14           ` skaller [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-02-22 10:25 David Teller
2007-02-22 10:42 ` [Caml-list] " Andrej Bauer
2007-02-22 12:41   ` skaller
2007-02-22 13:55     ` David Teller
2007-02-22 15:44       ` Jon Harrop
2007-02-22 19:45       ` Tom
2007-02-22 23:26         ` skaller
2007-02-22 15:28     ` Andreas Rossberg
2007-02-22 15:57       ` Till Varoquaux
     [not found]         ` <45DDC424.2020804@ens-lyon.org>
2007-02-22 16:57           ` Till Varoquaux
2007-02-22 17:19             ` brogoff

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=1172340850.5345.39.camel@rosella.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=bhurt@spnz.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=lukstafi@gmail.com \
    /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).