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
Recursive module types #4899
Comments
Comment author: @gasche It is possible to work around the lack of this feature by wrapping your signature inside a recursive module (this is actually a generic workaround for the problem "recursion between such and such structure item is not allowed"): module rec Tool : sig The downside is that you have to repeat the signature in the recursive module signature and implementation (recursive module must have a signature). Otherwise, it works relatively well: module rec OddTool : Tool.S = struct let test = One issue I quickly ran into while experimenting on this is that recursion is closed, and you may have wished it to be open. You can weaken the global signature with "with type = ..." equations, but this won't apply to recursive occurrences of the module type, making it useless. module rec OddTool : Tool.S with type t = unit = struct match EvenTool.process () with I don't know how to work around this. |
Comment author: @garrigue Just as a complement to gasche's note, there is actually no need to duplicate the module type definition. If a recursive module contains only type definitions, the body can be omitted. module rec Tool : sig This is a standard technique. |
Comment author: @garrigue The description was a bit misleading. |
Original bug ID: 4899
Reporter: marc_defalco
Assigned to: @garrigue
Status: closed (set by @garrigue on 2011-12-14T08:25:34Z)
Resolution: not a bug
Priority: normal
Severity: feature
Category: ~DO NOT USE (was: OCaml general)
Related to: #6818
Monitored by: @jberdine
Bug description
It is not possible to refer to a module type inside its definition, an Unbound_modtype error is thrown.
Additional information
In the light of first-class modules it is quite natural to want such restriction to be lifted.
For example consider the following module type :
module type TOOL = sig
type t
val process : t -> (module TOOL) option
end
allowing to define the usual pattern for tool-based widgets (the widget delegates event processing to the current tool, which returns a possible new selected tool).
The text was updated successfully, but these errors were encountered: