caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: keiko@kaba.or.jp
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Type constraints
Date: Thu, 09 Dec 2004 10:27:35 +0900 (JST)	[thread overview]
Message-ID: <20041209.102735.45228995.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <20041209.095602.74680404.keiko@kaba.or.jp>

From: nakata keiko <keiko@kaba.or.jp>

> > > This does not answer to me why this works,
> > >
> > > #type t = { t : 'a. 'a -> 'a}
> > >
> > > #let v = let module M = struct let t x = x end in {t = M.t} in (v.t 5, 
> > > v.t true)
> 
> I have the impression that if the above code is type checked,
> then, something like the following code could be type checked.
> What is the differences?
> 
> > > #let v : 'a. 'a -> 'a = let module M = struct let t x = x end in  M.t 
> > > in (v 5, v true)

These two examples use different kinds of polymorphism.
In the first case, the data structure ensures the polymorphism,
meaning that even if the type of the data structure is made
non-generalizable, you can still extract a polymorphic value from it
later.
That's why you can pass such values to functions, and use them
polymorphically inside (which you cannot do with normal variables.)

A simple example of the difference is
   (fun v -> (v.t 5, v.t true)) {t = fun x -> x}
vs.
   (fun v -> (v 5, v true)) (fun x -> x)

There is currently no way to make a first-class polymorphic value in
ocaml without using either record or object.
(There is no theoretical limitation, just we could never come up with
the right syntax for introduction and elimination.)

Jacques Garrigue


  reply	other threads:[~2004-12-09  1:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-06 19:55 Jim Farrand
2004-12-07  7:12 ` [Caml-list] " Alain Frisch
2004-12-07 13:43   ` Damien Doligez
2004-12-07 14:57     ` Andreas Rossberg
2004-12-07 17:44       ` Damien Doligez
2004-12-07 18:08         ` Alain Frisch
2004-12-07 21:04           ` Damien Doligez
2004-12-07 21:43             ` Alain Frisch
2004-12-08  3:30               ` nakata keiko
     [not found]                 ` <8002B033-4906-11D9-8195-000D9345235C@inria.fr>
2004-12-09  0:56                   ` nakata keiko
2004-12-09  1:27                     ` Jacques Garrigue [this message]
2004-12-08 10:53               ` Damien Doligez
2004-12-08 12:39                 ` Alain Frisch
2004-12-08 14:23                   ` Jacques Garrigue
2004-12-09  3:07                     ` skaller
2004-12-09  4:53                       ` Jacques Garrigue
2004-12-08 16:10                 ` Xavier Leroy
2004-12-07 18:13         ` William Lovas
2004-12-08  0:27           ` Jacques Garrigue
2004-12-07 18:41         ` Boris Yakobowski
2004-12-07 19:38   ` Jim Farrand

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=20041209.102735.45228995.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=keiko@kaba.or.jp \
    /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).