New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
anonymous functions with optional arguments #5748
Comments
Comment author: @garrigue Repeating the message of the caml-list (feedback request at the end): OCaml 4.00 is much more agressive in propagating expected types when typing Specifically, this is this behavior: val f : (unit -> unit) -> unit let () = f g This code triggers automatic discarding of the optional arguments of g, But for this we need to first infer the type of the argument, to see that I was not aware that this feature was widely used, and the behavior in 4.00.0
An inline function doesn't enter this category. I'm pondering what to do about this. Not propagating types to function arguments seems fine, but for variant and record How much do you rely on that? |
Comment author: @alainfrisch Jacques: what do you call "upward" propagation? Propagating the expected types down the AST? Wouldn't it be possible to trigger the erasure of an optional argument "on the fly" when reaching a lambda node, if the expected type asks for a function type without this optional argument? That said, I'm not a big fan of the automatic erasure of optional arguments (it looks rather fragile, and not so useful). |
Comment author: @mjambon This problem occurs in two spots in a ~100K-line code base and I don't see much more need for it in the future. The macro we're using is FILTER provided by mikmatch_pcre: let f = FILTER int eos;;val f : ?share:bool -> ?pos:int -> string -> bool = List.filter (FILTER int eos) [ "-123"; "a"; "0"; "-1.2" ];;
|
Comment author: @mshinwell I think the lack of activity (more than four years) on this PR suggests that there isn't a problem in this area at present. |
Original bug ID: 5748
Reporter: @mjambon
Assigned to: @garrigue
Status: closed (set by @mshinwell on 2017-03-07T13:40:55Z)
Resolution: not a bug
Priority: normal
Severity: minor
Platform: any
Version: 4.00.0
Target version: later
Category: typing
Related to: #6352
Monitored by: mehdi @ygrek Camarade_Tux @hcarty
Bug description
In OCaml 4.00, anonymous functions with optional arguments can no longer be passed to a higher order function that doesn't know expect optional arguments. Here is an example:
let f g = g () ;;
(* works in 3.12 and 4.00 *)
let g = fun ?opt () -> () in
f g
;;
Here is what no longer works in OCaml 4.00.0 but used to work in 3.12.1:
f (fun ?opt () -> ()) ;;
Error: This function should have type unit -> 'a
but its first argument is labelled ~?opt
This breaks some of our code where the anonymous function is generated by a Camlp4 macro.
The text was updated successfully, but these errors were encountered: