Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Type inference problem
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Remi VANICAT <vanicat@l...>
Subject: Re: [Caml-list] Type inference problem
Vasilij Karpow <malc@boblycat.com> writes:

> Can anyone explain why O'Caml specializes the following:
> 
> let simple ?fn list =
>   let fn = match fn with
>   | Some fn -> fn
>   | None -> fun t -> t in
>   let rec print = function
>     | [] -> ()
>     | x :: xs -> print_endline (fn x); print xs
>   in
>   print list
> 
> let _ =
>   simple ["1"];
>   simple ~fn:(fun i -> string_of_int i) [1]
> 
> 
> to: val simple : ?fn:(string -> string) -> string list -> unit

it's easy. If the value was polymorphic, you would be authorized to
write :

simple [1; 2; 3; 4; 5]

which is unsound.


-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr