List Info

Thread: "ocaml_beginners"::[] How to organize these "related" functors ?




"ocaml_beginners"::[] How to organize these "related" functors ?
country flaguser name
France
2008-05-20 01:44:30

Hi !

I unsuccesfully tried to replicate with functors what was done here with simple modules :

----------------------------------------------------------
module rec Point :
sig
type t = int * int
val compare : 'a -> 'a -> int
val ( ++ ) : int * int -> int * int -> int * int
...
val connect : (int * int) list -> int * int -> PointSet.t
end
=
struct
type t = int * int

let compare = compare

let ( ++ ), ( -- ) =
...

let connect ways p =
List.fold_left
(fun acc d ->
PointSet.add (p ++ d) acc)
PointSet.empty
ways
end

and PointSet : Set.S with type elt = Point.t = Set.Make ( Point )

"connect" is a Point function that returns a set of points.

----------------------------------------------------------
Here is functor Make that returns a graph module for a specified element type, in file "digraph.ml"; :

module Make ( Val : Set.OrderedType ) :
sig
module ValSet :
sig
type elt = Val.t
type t = Set.Make(Val).t
end
module ValMap :
sig
type key = Val.t
type 'a t = 'a Map.Make(Val).t
end
type elt = Val.t
type t = ValSet.t ValMap.t
val adj_vertices : ValMap.key -> 'a ValMap.t -> 'a
val degree : ValMap.key -> ValSet.t ValMap.t -> int
val empty : 'a ValMap.t
...
end
=
struct
module ValSet = Set.Make( Val )
module ValMap = Map.Make( Val )

type elt = Val.t
type t = ValSet.t ValMap.t

let adj_vertices = ValMap.find

let degree = ( <<- ) ValSet.cardinal <<- adj_vertices

let empty = ValMap.empty

...
end

Now my problem is to add to Digraph.Make a new function "find_loops"; that takes a Digraph for parameter and returns a set of Digraphs of same type.

( Exactly what was done with upper recursive modules Point et PointSet, but parametrized here. )

Please how to write this ?

Thanks,

Fabrice

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )