Browse thread
Polymorphic variant typing
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2005-02-15 (22:19) |
From: | Olivier_Pérès <olivier.peres@l...> |
Subject: | Re: [Caml-list] Polymorphic variant typing |
Gilles Dubochet a écrit : > 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 Now, how about this : let incr x g = match x with | `Int i -> `Int (i+1) | x -> g x;; Doesn't it look like your code ? OCaml 3.08.2 types it as follows : val incr : ([> `Int of int ] as 'a) -> ('a -> ([> `Int of int ] as 'b)) -> 'b = <fun> This is more like it ! incr (`Int 1) (fun (`Int i) -> (`Int (i+1)));; - : [> `Int of int ] = `Int 2 incr (`Float 1.0) (fun x -> match x with (`Float f) -> (`Float (f +. 1.0)) | x -> x);; - : [> `Float of float | `Int of int ] = `Float 2. It remains to understand why the type of incr should depend upon the order in which the arguments are given... Yours, Olivier.