caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David Brown <caml-list@davidb.org>
To: Gilles Dubochet <dubochet@urbanet.ch>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Polymorphic variant typing
Date: Tue, 15 Feb 2005 16:43:24 -0800	[thread overview]
Message-ID: <20050216004324.GA1537@old.davidb.org> (raw)
In-Reply-To: <7bf1f3b95c18eeda0ed169eb7f73d6f0@urbanet.ch>

On Tue, Feb 15, 2005 at 09:28:52PM +0000, Gilles Dubochet wrote:
> Hello everyone,
> 
> The following O'Caml expression:
> let incr g x = match x with
> 	| `Int i -> `Int (i+1)
> 	| x -> (g x);;
> 
> Receives type:
> (([> `Int of int ] as 'a) -> ([> `Int of int ] as 'b)) -> 'a -> 'b
> 
> Why? I am quite astonished. I would have expected a type more like:
> ([> ] -> [> ]) -> [> `Int of int ] -> [> `Int of int ]
>
> or in Wand or Rémy-like row variable notation with which I am a little 
> more comfortable (I am not exactly sure the preceding type is correct 
> in the 'at leat - at most' notation of O'Caml):
> ([ 'a ] -> [ 'b ]) -> [ `Int of int | 'a ] -> [ `Int of int | 'b ]
> 
> Could anyone be kind enough to give me some clues about where to look 
> at to find an explanation or even better, explain me what is going on? 
> I am particularly puzzled by the fact that the g function's *argument* 
> type is 'at least `Int of int'. This rejects the following code which 
> seems intuitively correct:
> incr (function `Float f -> `Float (f+.1.));;

We know that 'incr' can take a [> `Int of int] for 'x', since it matches
is.  The only way to know that it isn't going to call 'g' with one of these
would be to do a flow analysis of the code.  The type system is not based
on this type of analysis, but is determined statically.

The polymorphic types are not really dynamic types.  A particular type used
in a given call will have a specific type, and in this instance, it must
always contain [> `Int of int].

Dave


      parent reply	other threads:[~2005-02-16  0:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-15 21:28 Gilles Dubochet
2005-02-15 22:21 ` [Caml-list] " Olivier Pérès
2005-02-15 23:15   ` Gilles Dubochet
2005-02-16  0:36 ` Jacques Garrigue
2005-02-16  1:21   ` Gilles Dubochet
2005-02-16  6:40     ` Jacques Garrigue
2005-02-16 10:12       ` Radu Grigore
2005-02-16  0:43 ` David Brown [this message]

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=20050216004324.GA1537@old.davidb.org \
    --to=caml-list@davidb.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=dubochet@urbanet.ch \
    /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).