From: Xavier Clerc <xcforum@free.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Question about polymorphic variants
Date: Fri, 28 Oct 2005 14:27:34 +0200 [thread overview]
Message-ID: <E2B22BDD-C8AE-4D16-B805-5231D086A942@free.fr> (raw)
In-Reply-To: <20051028.205957.68033883.garrigue@math.nagoya-u.ac.jp>
Le 28 oct. 05 à 13:59, Jacques Garrigue a écrit :
> 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.)
This is indeed the question I was asking to myself ...
> The answer is yes, with a counter-example using
> the difference in representation between normal arrays and float
> arrays.
In this counter-example, it is not clear to me whether the possible
problem is type-related or runtime-related. I mean, would this
counter-example still hold if arrays were both boxed or both unboxed ?
> 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...
Does this mean that inferring "[< `Off | `On] list -> int list" would
be perfectly safe in the example above ?
(by saying so, I am not pleading for any compiler change, I am just
trying to organize my thoughts)
Thanks for you clear (and fast) answer.
Regards
next prev parent reply other threads:[~2005-10-28 12:27 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 ` [Caml-list] " Jacques Garrigue
2005-10-28 12:27 ` Xavier Clerc [this message]
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=E2B22BDD-C8AE-4D16-B805-5231D086A942@free.fr \
--to=xcforum@free.fr \
--cc=caml-list@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