caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Polymorphic variant typing
@ 2005-02-15 21:28 Gilles Dubochet
  2005-02-15 22:21 ` [Caml-list] " Olivier Pérès
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Gilles Dubochet @ 2005-02-15 21:28 UTC (permalink / raw)
  To: caml-list

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.));;

Thank you.
Cheers,
Gilles.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-02-16 10:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-15 21:28 Polymorphic variant typing 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 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).