-
Notifications
You must be signed in to change notification settings - Fork 2
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
Generated OCaml interface's style #3
Comments
Yeah it is a bit clunky as is. However, it's currently using the penultimate Also, with requiring all of the args to be named (or optional with So, while I agree it's not the typical style, it will probably be around for a bit as I'm working on some other features before this one. |
The requiring all args to be named is also questionable in terms of taste. |
Yeah I think ultimately something like a command line flag to chose would be nice. Or just smarter handling of the args in general would be welcome. Ideally, I wouldn't want the binding generator to force a certain style on a user, but as of now that is essentially what it's doing. Personally I prefer labels (eg I open Base on every project), and so that is what I implemented. But I definitely understand that that isn't the style or practice of everyone. So eventually it's something I would like to see addressed. |
I was thinking of some ideas on how to address this in a nice way. The labeled args and the penultimate However, with the latest updates to the Here are some examples of what I mean. Avoiding penultimate unitFor example, the way it differentiates between an instance method that takes no arguments and a attribute/property is with the penultimate val age : t -> string
val name : t -> unit -> string class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def name(self):
return(self.name) However, with attributes, it could be done like this: val age : t -> string
[@@py_fun_type attribute]
val name : t -> string And Class methods vs. instance methodsCurrently, any value spec that takes a positional val f : t -> ... -> unit -> ... You could envision an odd Python class method that actually takes an instance of that class as the first argument. To differentiate, currently val g : foo:t -> ... -> unit -> ... In this way it knows that its a class method and not an instance method. However, with attributes, the above could be simplified. val f : t -> ... -> unit -> ...
val g : t -> ... -> unit -> ...
[@@py_fun_type class_method] That would get rid of the need for labeled arguments in that case. (I still need to check on if things get weird with the bindings if you mix positional, labeled, and optional arguments...Perhaps in the beginning, you will not be allowed to mix them? I'm not sure yet.) Non-erasable argsThe other place penultimate unit is necessary would be to make sure arguments are erasable. val f : t -> foo:string -> ?bar:string -> unit -> string Currently, I enforce this in Anyway, what do you think of this @UnixJunkie? |
I don't follow everything, but here are some comments:
|
Yeah good catch with the int/string thing...just a typo there. And thanks for the input on your other points as well. Anyway, I will play around with some of these ideas and see how they go. I will leave the issue open for now and in the meantime, feel free to add any additional thoughts you might have about the matter as they come up. |
It would be nice if people don't have to put this penultimate unit
at the end of a function declaration (in the *_specs.txt file).
Once you are in ocaml, having to add those () to call a function
doesn't look good.
But, I admit it's just a question of style.
The text was updated successfully, but these errors were encountered: