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
module type LABEL=sigtypetvalequal: t -> t -> boolvalcompare: t -> t -> intvalto_string: t -> stringvalpp: Format.formatter -> t -> unitendmoduleMake(Label: LABEL) =structtypet = {
label: Set.Make(Label).t
}
[@@deriving show]
end
And I get:
Error: broken invariant in parsetree: Functor application not allowed here.
Is there a reason why this shouldn't work? The code compiles if i create the module beforehand module S = Set.Make(Label) and then use S.t instead.
The text was updated successfully, but these errors were encountered:
Meh, I think I figured it out, Set.Make(Label).pp is then called in the body of the generated function, right? So the generator could do let module S = Set.Make(Label) in for each module in the type, however if the module has side effects, this probably wouldn't be a good idea...
It may be possible to name the module carefully: if each occurrence of a functor application (in a module path that we want to derive from) is turned into a binding on the fly, we should be able to preserve the evaluation behavior of the original program. (What we don't want is to evaluate the functor application several times in the generated code.) But this is a bit delicate, and there may be case where this would change the type signature of the program (type equalities lost in the renaming, this kind of thing).
I think that the more robust approach is to bail out when we see this, and ask the user to do the let-binding themselves, so that they understand this is happening. The error message could be better than it is today (it looks like ppx_deriving is not saying anything here, the error in the generated code is caught by the compiler later on), but it would be the same behavior.
I have this code:
And I get:
Is there a reason why this shouldn't work? The code compiles if i create the module beforehand
module S = Set.Make(Label)
and then useS.t
instead.The text was updated successfully, but these errors were encountered: