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
Compiler rejects `... with module ...' --- am I being stupid? #2830
Comments
Comment author: administrator Dear Norman,
Let me try to explain what's going on. Then we can argue later Currently, OCaml requires "with" constraints on signatures to add (sig type t end) with type t = int is OK, since we're adding the information that t is int. Similarly, (sig type t = int end) with type t = int is OK too, since we're not changing anything. However, (sig type t = int end) with type t = bool is rejected on the grounds that we would get sig type t = bool end which is not a subtype of sig type t = int end This restriction is somewhat arbitrary: we could interpret "with" as Coming back to your example, let's expand some of the signatures:
i.e. module type INTERP' = sig
Here, A has principal signature so INTERP' with module Ast = A would be sig and the system complains that this is not a subtype of INTERP', However, you can tell Caml that it is so, as follows: module MkInterp' (A : AST') : It typechecks, and with some luck maybe it does what you want :-) Best wishes,
|
Comment author: administrator Explanations of the implemented behavior seem to have satisfied the user. |
Original bug ID: 427
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Messieurs,
I'm not sure if I'm just being stupid or if I've tripped over a bug in
OCaml version 3.01. I'm trying to put together a fairly heavily
functorized interpreter, and the compiler refuses to permit me
an annotation on the signature of a functor. I've boiled it down
to the following small test case:
module type VALUE' = sig
type userdata
end
module type AST' = sig
module Value : VALUE'
end
module type INTERP' = sig
module Value : VALUE'
module Ast : AST' with module Value = Value
end
module MkInterp' (A : AST') : INTERP' with module Ast = A = struct
module Value = A.Value
module Ast = A
end
The compiler complains about the `with' constraint on the result of
MkInterp'.
Can you tell me please if I am doing something stupid? How should I proceed?
Thanks,
Norman
P.S. Didn't know whether to send to caml or caml-bugs, so I sent to
both :-(
The text was updated successfully, but these errors were encountered: