Browse thread
module type...
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Pietro Abate <Pietro.Abate@a...> |
| Subject: | Re: [Caml-list] module type... |
Thanks John.
On Thu, Nov 11, 2004 at 07:56:10PM +1100, skaller wrote:
> By coercing TermType to ElType, you have coerced 'int' to 't',
> where 't' is an abstract type, in other words the coercion is hiding
> the representation. There are two ways around this
ok, I got the problem... but neither of your solutions solve my more
general problem as I need ElType.t to be an abstract data type as I'm
using it in a functor...
now it says:
This expression has type int but is here used with type
SetOfTerm.Set.elt = TermType.t
for the same reason as before, but I can't change the ElType.t
without breaking the functor
[....]
module MakeSet =
functor (Q : ElType) -> functor (SetFunc : SetFuncType) -> struct
module Set = SetFunc ( struct
type t = Q.t
let compare = compare
end
)
[....]
below the extended version of the problem with the same error...
any advice on how to modify my modules/classes design to overcome this
problem ? what I'm trying to do is to have set, setofset, setofsetofset
etc using the same code base and functors...
:)
p
--------------------------------
module type ElType =
sig
type t
val copy : t -> t
val to_string : t -> string
end
module type OrderedType =
sig
type t
val compare : t -> t -> int
end
module type SetFuncType =
functor (Ord : OrderedType) ->
sig
type elt = Ord.t
type t
val empty : t
val compare : t -> t -> int
val add : elt -> t -> t
end
module MakeSet =
functor (Q : ElType) -> functor (SetFunc : SetFuncType) -> struct
module Set = SetFunc ( struct
type t = Q.t
let compare = compare
end
)
class set ?(el=[]) () =
object(self)
initializer self#add el
val mutable s = Set.empty
method add el =
s <- List.fold_left ( fun s' e -> Set.add e s' ) s el
end
end
module TermType : ElType =
struct
type t = int
let copy t = t
let to_string t = "this is a string"
end
;;
module SetOfTerm = MakeSet (TermType) (Set.Make);;
(* ------------------ *)
module SetOfTermType : ElType =
struct
type t = SetOfTerm.set
let copy t = t
let to_string t = "this is an other string"
end
;;
module SetOfSet = MakeSet (SetOfTermType) (Set.Make);;
let newset_naked ?(el=[]) () = new SetOfTerm.set ~el:el
let newset ?(el=[]) () = (`Set (new SetOfTerm.set ~el:el))
let newsetofset ?(el=[]) () = (`Set (newset ~el:el ()))
let a = newset_naked ~el:[1;2] ();;
let b = newsetofset ~el:[a] ();;
--
++ "All great truths begin as blasphemies." -George Bernard Shaw
++ Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html