* [Caml-list] module types
@ 2004-06-03 17:26 Damien
2004-06-03 18:33 ` John Carr
2004-06-04 8:41 ` Julien Signoles
0 siblings, 2 replies; 4+ messages in thread
From: Damien @ 2004-06-03 17:26 UTC (permalink / raw)
To: Caml List
Hi,
module type T = sig type 'a t end
module F(M: T): sig
type a
type t = a M.t
(* plus a lot of values... *)
end = struct
type a = unit
type t = unit M.t
end
I would like to re-write it like this :
module type T = sig type 'a t end
module type O =
sig
type a
type t
(* plus a lot of values... *)
end
module F(M: T): O with type t = a M.t =
struct
type a = unit
type t = unit M.t
end
but I can't, because "a" is unknown...
(of course, I want to keep it abstract)
any idea ?
thanks,
damien
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] module types
2004-06-03 17:26 [Caml-list] module types Damien
@ 2004-06-03 18:33 ` John Carr
2004-06-03 23:13 ` skaller
2004-06-04 8:41 ` Julien Signoles
1 sibling, 1 reply; 4+ messages in thread
From: John Carr @ 2004-06-03 18:33 UTC (permalink / raw)
To: Caml List
I also have a problem with module types. Suppose I have
module type T = sig type t val f : t -> string end
If I want to declare a module implementing this signature I can write
module X : T with type t = int
but this similar declaration is not allowed
module Y : T with type t = A | B | C
The manual implies this restriction is intentional, a result of not
allowing unnamed constructor types. I also tried
module Y : sig include T type t = A | B | C end
but the compiler considered this to be an illegal duplicate
definition of type t.
1. Is there a reason not to allow (A | B | C) as an anonymous
type declaration?
2. Is there a way to do what I want without declaring the type name
outside the module? I prefer to limit the scope of type names.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] module types
2004-06-03 18:33 ` John Carr
@ 2004-06-03 23:13 ` skaller
0 siblings, 0 replies; 4+ messages in thread
From: skaller @ 2004-06-03 23:13 UTC (permalink / raw)
To: John Carr; +Cc: Caml List
On Fri, 2004-06-04 at 04:33, John Carr wrote:
> 1. Is there a reason not to allow (A | B | C) as an anonymous
> type declaration?
Standrd Sum types are generative: A | B is not a type, a binder is
required.
Use a polymorphic variant instead:
[`A | `B | `C]
--
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850,
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] module types
2004-06-03 17:26 [Caml-list] module types Damien
2004-06-03 18:33 ` John Carr
@ 2004-06-04 8:41 ` Julien Signoles
1 sibling, 0 replies; 4+ messages in thread
From: Julien Signoles @ 2004-06-04 8:41 UTC (permalink / raw)
To: Damien; +Cc: Caml List
> module type T = sig type 'a t end
> module F(M: T): sig
> type a
> type t = a M.t
> (* plus a lot of values... *)
> end = struct
> type a = unit
> type t = unit M.t
> end
>
> I would like to re-write it like this :
>
> module type T = sig type 'a t end
> module type O =
> sig
> type a
> type t
> (* plus a lot of values... *)
> end
> module F(M: T): O with type t = a M.t =
> struct
> type a = unit
> type t = unit M.t
> end
>
> but I can't, because "a" is unknown...
> (of course, I want to keep it abstract)
>
> any idea ?
I already encountered this problem a while ago. I solved it by using the
following technic:
module type T = sig type 'a t end
module type O = sig type a type t end
type b = unit
module F(M:T): O with type t = b M.t and type a = b =
struct
type a = unit
type t = unit M.t
end
In the signature of the above structure, [b] should be abstract in order
to keep [a] abstract. Sadly, this technic introduces a new type definition
but I don't see a better way to solve this problem.
Hope this helps,
Julien Signoles
--
mailto:Julien.Signoles@lri.fr ; http://www.lri.fr/~signoles
"In theory, practice and theory are the same,
but in practice they are different" (Larry McVoy)
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-06-04 8:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-03 17:26 [Caml-list] module types Damien
2004-06-03 18:33 ` John Carr
2004-06-03 23:13 ` skaller
2004-06-04 8:41 ` Julien Signoles
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox