Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* SIGNATURES *)
- module type VERTEX =
- sig
- type t
- type label
- val equal : t -> t -> bool
- val create : label -> t
- val label : t -> label
- end
- module type EDGE =
- sig
- type t
- type v
- type label
- val equal : t -> t -> bool
- val create : v -> v -> label -> t
- val label : t -> label
- val in_v : t -> v
- val out_v : t -> v
- end
- module type GRAPH =
- sig
- type t
- type v
- type e
- val init : unit -> t
- val insert_v : t -> v -> t
- val insert_e : t -> e -> t
- val fold_v : (v -> 'a -> 'a) -> t -> 'a -> 'a
- end
- (* STRUCTS *)
- module Vertex : VERTEX with type label = int =
- struct
- type t = int
- type label = int
- let equal v1 v2 = (v1 = v2)
- let create l = l
- let label l = l
- end
- module AbstractEdge(Vertex : VERTEX) : (EDGE with type v = Vertex.t and type label = string) =
- struct
- type v = Vertex.t
- type label = string
- type t = v * v * label
- let fst (x, _, _) = x
- let snd (_, x, _) = x
- let trd (_, _, x) = x
- let equal e1 e2 = ((fst e1) = (fst e2)) && ((snd e1) = (snd e2)) && ((trd e1) = (trd e2))
- let create v1 v2 l = v1, v2, l
- let label e = trd e
- let in_v e = fst e
- let out_v e = snd e
- end
- module Edge = AbstractEdge(Vertex)
Add Comment
Please, Sign In to add comment