You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 7175 Reporter: goswin Status: acknowledged (set by @damiendoligez on 2017-02-27T15:50:52Z) Resolution: open Priority: normal Severity: feature Category: language features
Bug description
I have C stubs that take a class as argument and the class needs to call the C stubs. So they are both dependent on the other and one has to use recursive modules. That gets rather long winded and hard to read for something that should be trivial.
I want to write:
external stub : #c -> unit = "stub"
class c = object
initializer stub self
end
I need to write:
module rec E : sig
val stub : #C.c -> unit
end = struct
external stub : #C.c -> unit = "stub"
end and C : sig
class c : object end
end = struct
class c = object(self)
initializer E.stub self
end
end
It might be a good idea to allow both static functions and class methods as external. Maybe this syntax:
class foo bar = object
val external stub : int -> foo -> unit = "stub"
method external method_stub : unit = "method_stub"
end
In this case method_stub would take class foo as first argument implicitly while stub can have it at any place (or not at all).
The text was updated successfully, but these errors were encountered:
class foo bar = object
val external stub : int -> foo -> unit = "stub"
end
makes sense, as an instance variable should be a value that can be overwritten in another copy of the object. I think a more sensible way to write what you want would be:
class foo bar = object
let module M = struct
external stub: int -> foo -> unit = "stub"
end in object
..
end
which is unfortunately not currently supported. In the future, I could imagine this becoming:
class foo bar = object
let external stub: int -> foo -> unit = "stub" in object
..
end
which is probably the most accurate way to write what you mean.
It is worth noting that, since class types are structural you can workaround your issue by just writing an explicit class type:
Writing out class types is tedious, more so with inheritance, even more so with recursive types. Writing out the types for Qt5 classes is nearly impossible.
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.
Original bug ID: 7175
Reporter: goswin
Status: acknowledged (set by @damiendoligez on 2017-02-27T15:50:52Z)
Resolution: open
Priority: normal
Severity: feature
Category: language features
Bug description
I have C stubs that take a class as argument and the class needs to call the C stubs. So they are both dependent on the other and one has to use recursive modules. That gets rather long winded and hard to read for something that should be trivial.
I want to write:
external stub : #c -> unit = "stub"
class c = object
initializer stub self
end
I need to write:
module rec E : sig
val stub : #C.c -> unit
end = struct
external stub : #C.c -> unit = "stub"
end and C : sig
class c : object end
end = struct
class c = object(self)
initializer E.stub self
end
end
It might be a good idea to allow both static functions and class methods as external. Maybe this syntax:
class foo bar = object
val external stub : int -> foo -> unit = "stub"
method external method_stub : unit = "method_stub"
end
In this case method_stub would take class foo as first argument implicitly while stub can have it at any place (or not at all).
The text was updated successfully, but these errors were encountered: