caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: xcforum@free.fr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Question about polymorphic variants
Date: Fri, 28 Oct 2005 20:59:57 +0900 (JST)	[thread overview]
Message-ID: <20051028.205957.68033883.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <589B1E9E-D4EC-4E03-9375-30670ED82BEB@free.fr>

From: Xavier Clerc <xcforum@free.fr>
> Then, I use this function in the following expression :
> 
> List.map f
> 
> which is in turn inferred as: _[< `Off | `On ] list -> int list
> 
> My question is about the meaning of the leading underscore in the  
> inferred type (given that I understand the meaning of the underscore  
> in an expression such as "Stack.create ()" that is inferred as: '_a  
> Stack.t).

This is exactly the same meaning: [< `Off | `On] has some form of
flexibility left, which you might see as a type variable, and as such
it obeys the same rules as type variables.

An example close to the above one would be:

# List.map (fun (x,y) -> x+1);;
- : (int * '_a) list -> int list = <fun>

Now you might wonder why '_a cannot be polymorphic in the above
example. That is, could there really be a definition of List.map such
that the polymorphic type would be dangerous (causing a segmentation
fault for instance.) The answer is yes, with a counter-example using
the difference in representation between normal arrays and float
arrays.
Actually, since this counter-example wouldn't apply to the above case
of polymorphic variants, this would probably be safe to leave the
polymorphic variant type as polymorphic...

Jacques Garrigue


  reply	other threads:[~2005-10-28 11:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-28  9:57 Xavier Clerc
2005-10-28 11:59 ` Jacques Garrigue [this message]
2005-10-28 12:27   ` [Caml-list] " Xavier Clerc
2005-10-29  0:26     ` Jacques Garrigue
2005-10-31 17:08       ` Xavier Clerc
2005-11-01  0:27         ` Jacques Garrigue
2005-11-04 13:20           ` Xavier Clerc
2005-11-07  3:11             ` Jacques Garrigue
2005-11-07 13:39               ` Xavier Clerc

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=20051028.205957.68033883.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=xcforum@free.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).