(sorry for any double-posting)

The problem is that in your declaration of h, the inferred type for f
is of the form (unit -> unit -> ...), and you use it with the
different type (unit -> ?a:'a -> unit -> ...).

Changing ?a to be the first parameter of f change f's type to (?a:'a
-> unit -> unit -> ...). OCaml knows that it can implicitly coerce
functions when the optional parameters appear in the first position.

This is explained in the manual :
http://caml.inria.fr/pub/docs/manual-ocaml/manual006.html#htoc39

> However, in the specific case where the expected type
> is a non-labeled function type, and the argument is
> a function expecting optional parameters, the compiler
> will attempt to transform the argument to have it match
> the expected type, by passing None for all optional parameters.

A fix is to add an annotation when defining h :

let h (f : _ -> ?a:_ -> _) =
 f () ()

# let () = h f;;
bouh!
bouh!

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to