caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Till Varoquaux" <till.varoquaux@gmail.com>
To: "David Teller" <David.Teller@ens-lyon.org>,
	OCaml <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Feature request : Tuples vs. records
Date: Thu, 22 Feb 2007 17:57:09 +0100	[thread overview]
Message-ID: <9d3ec8300702220857u15e73d6eq8f48066e1a307626@mail.gmail.com> (raw)
In-Reply-To: <45DDC424.2020804@ens-lyon.org>

On 2/22/07, David Teller <David.Teller@ens-lyon.org> wrote:
> Sounds interesting. Do you have documentation on this use of records for
> general recursivity ?
>
> Thanks,
>  David

I really put my foot in my mouth for my previous post (I had just read
the part about unlabeled tupple in SML...). Anyway here I come:

let rec f a b=
 if false then
  (*Although this is never called it breaks polymorphisme*)
  f print_string "a";
 a b;;

And here is the same using records (and having a more general type):

type my_rec={f:'a 'b.('a -> 'b) -> 'a -> 'b};;

let rec r={
 f=(fun a b ->
     if false then
      (*Polymorphisme is not b0rken...*)
      r.f print_string "a";
     a b
 )
};;
r.f print_int 5;;

This is a very useless example. Thierry Martinez (I know you are
reading us) had a cool example and some of the fixpoint operators on:
http://okmij.org/ftp/ML/fixpoints.ml
use this trick.

Cheers,
Till




>
> Till Varoquaux a écrit :
> > Another simple difference is that you have to declare the type of the
> > records whereas types of tupples can be infered. Since the typechecer
> > actually uses the type information given, you can use polymorphic
> > fields to implement general reccursivity.
> > I would also mention row polymorphisme and "mutable" as notable
> > differences. You could also note that they are not always
> > interchangeable: whilst you wouldn't want to define a new record type
> > for every tupple you use (very verbose), direct access to a defined
> > field and the "with" keyword (e.g let b={a with x=1}) make records
> > nice to handle large structures.
> >
> > Till
>
>


  parent reply	other threads:[~2007-02-22 16:57 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2007-02-22 17:19             ` brogoff
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

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=9d3ec8300702220857u15e73d6eq8f48066e1a307626@mail.gmail.com \
    --to=till.varoquaux@gmail.com \
    --cc=David.Teller@ens-lyon.org \
    --cc=caml-list@yquem.inria.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).