I want to define the two types below:
type foo = { bar : bar; }
class bar = object val mutable foo : foo list = [] end
Is there another way of doing this other than:
# type 'a foo = { bar : 'a; }
class bar = object val mutable foo : #bar foo list = [] end;;
type 'a foo = { bar : 'a; }
class bar : object val mutable foo : #bar foo list end
I don't want any 'a foo other than 'a = #bar. It is too easy to create a
baz foo and then much later get a type error when trying to use it as
bar foo. I want the error where the foo gets created.
MfG
Goswin
_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
The alternative is to use a recursive module, but this is actually
more verbose.
module rec M : sig
type foo = { bar : M.bar; }
class bar : object val mutable foo : foo list end
end = struct
type foo = { bar : M.bar; }
class bar = object val mutable foo : foo list = [] end
end
You can avoid a bit of the verboseness by splitting types and values,
since recursive modules built only from types require no duplication.
module rec M : sig
type foo = { bar : M.bar; }
class type bar = object val mutable foo : foo list end
end = M
class bar : M.bar = object val mutable foo : M.foo list = [] end
You still need to provide an explicit interface for bar.
Hope this helps,
Jacques Garrigue
Thanks, it does. It isn't nice but it does solve the problem. Now I have
to decide what I live with. 'a foo uglyness or module rec uglyness.
It is too bad a simple
type foo = ...
and class bar = ...
doesn't work.
MfG
Goswin