caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* type troubles with functors
@ 2005-06-22  4:53 Scott Duckworth
  2005-06-22  6:48 ` [Caml-list] " Pietro Abate
  0 siblings, 1 reply; 3+ messages in thread
From: Scott Duckworth @ 2005-06-22  4:53 UTC (permalink / raw)
  To: caml-list

I'm having trouble figuring out a way to represent functor modules as
types in a module type definition.  For lack of a better way of
explaining it, here's the problem I'm having in code:
*************************************
(* OrderedSet.mli *)
(* Ordered sets over ordered types *)

module type OrderedType = (* same as in .ml file *)
module type S = (* same as in .ml file *)
module Make (Ord : OrderedType) : S with type elt = Ord.t
*************************************
(* OrderedSet.ml *)
(* Ordered sets over ordered types *)

module type OrderedType = sig
	type t
	val compare : t -> t -> int
end

module type S = sig
	type elt
	type t
	val to_list : t -> elt list
	val to_set : t -> EltSet.t     (* PROBLEM *)
	(* ... *)
end

module Make (Ord : OrderedType) = struct
	module EltSet = Set.Make(Ord)      (* THIS IS WHAT I WANT TO RETURN *)
	type elt = Ord.t
	type t = { l : elt list; s : EltSet.t }
	let to_list s = s.l
	let to_set s = s.s    (* THIS IS WHERE I WANT TO RETURN A SET *)
	(* ... *)
end
*************************************
I realize that EltSet.t is not defined at the two points I have noted
a problem, I'm simply stating my intention.  The problem is that
OrderdSet.S does not know the OrderedSet.OrderedType that will be used
in OrderedSet.Make, but it does know that it will be of type Set.S.t. 
(This is one instance where I wish Set was implemented as a
parameterized type, not a functor.)

My question is, how can I correctly type to_set?  I have tried many
different configurations of Set.Make and Set.S, but none of them have
worked.  If anyone knows how this can be done in OCaml's type system,
please let me know.  Thanks!
-- 
Scott Duckworth


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-06-22  7:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-22  4:53 type troubles with functors Scott Duckworth
2005-06-22  6:48 ` [Caml-list] " Pietro Abate
2005-06-22  7:50   ` Virgile Prevosto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).