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
external functions can't be specified with a type that is a function #7176
Comments
Comment author: @alainfrisch The number of syntactic "->" in external declaration defines the arity of the external function. This information is required to generate proper code to call the function. |
Comment author: goswin and why doesn't t carry that information? |
Comment author: @alainfrisch Indeed, one could probably allow the simple case where the type is entirely described by a named functional type: type t = int -> int external foo: t = "..." But the fact that: type t = int -> int external foo: int -> t = "..." is different from: type t = int -> int external foo: int -> int -> int = "..." is a feature. |
Comment author: junsli I see, interesting. It is actually documented already: http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#sec414 |
Comment author: goswin From the docs: Maybe an exception should be made when only an abbreviated type is given. That should be a small change. I would say in your example external foo: int -> t = "..." The extra () denoting a single return type. Just like int -> (int -> int) -> int has 2 arguments, one of them being a closure the foo returns a closure. From the docs: "For instance,
f has arity 1, but g has arity 2. This allows a primitive to return a functional value (as in the f example above): just remember to name the functional return type in a type abbreviation." I think that's inconsistent. f and g should both have arity 1. The syntax with extra () around functional return types might actually make it clearer for ocaml function in general that they consume the first argument(s) and return a closure consuming any followup arguments. Execution wise there is a difference between let f x y = Printf.printf "x = %d, y = %d, x+y = %d\n" x y (x+y); x+y Why not show this in the type? |
Comment author: @damiendoligez
That's really not a good idea. If we start using parentheses like this, how do you explain the associativity of "->" ? Currently you can just say that a->b->c is the same as a->(b->c).
What you want is function types with arity, maybe a good idea IMO, but it requires huge changes in the type system and in the language syntax. We certainly are not going to do it just to solve a minor problem in an obscure part of the system.
Introducing a special case: rarely a good thing... You have to do a cost/benefit analysis here. |
Comment author: goswin
Yes. Which the () would show in a simple way. But you have me convinced. The change in the type system would far too large and you would have to solve the problem of passing int->int->int to a function expecting int->(int->int) or vice versa and so on. The issue can be closed, it's as documented and I see why. |
Original bug ID: 7176
Reporter: goswin
Status: closed (set by @mshinwell on 2016-12-07T17:55:56Z)
Resolution: not a bug
Priority: normal
Severity: feature
Version: 4.02.3
Target version: 4.03.1+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @hcarty
Bug description
external expects a type that is a function. But it seems to require an actual "->" token instead of a type that represents a function.
Steps to reproduce
type t = c -> unit;;
type t = c -> unit
external stub : t = "stub";;
Error: External identifiers must be functions
The text was updated successfully, but these errors were encountered: