Guest User

Untitled

a guest
Apr 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 1.23 KB | None | 0 0
  1. (* SIGNATURES *)
  2. module type VERTEX =
  3. sig
  4.   type t
  5.   type label
  6.  
  7.   val equal : t -> t -> bool
  8.   val create : label -> t
  9.   val label : t -> label  
  10.  
  11. end
  12.  
  13. module type EDGE =
  14. sig
  15.   type t
  16.   type v  
  17.   type label
  18.  
  19.   val equal : t -> t -> bool
  20.   val create : v -> v -> label -> t
  21.   val label : t -> label
  22.   val in_v : t -> v
  23.   val out_v : t -> v
  24. end
  25.  
  26. module type GRAPH =
  27. sig
  28.   type t
  29.   type v
  30.   type e
  31.  
  32.   val init : unit -> t
  33.   val insert_v : t -> v -> t
  34.   val insert_e : t -> e -> t
  35.   val fold_v : (v -> 'a -> 'a) -> t -> 'a -> 'a
  36. end
  37.  
  38. (* STRUCTS *)
  39. module Vertex : VERTEX with type label = int =
  40. struct
  41.   type t = int
  42.   type label = int
  43.  
  44.   let equal v1 v2 = (v1 = v2)
  45.   let create l = l
  46.   let label l = l
  47. end
  48.  
  49.  
  50. module AbstractEdge(Vertex : VERTEX) : (EDGE with type v = Vertex.t and type label = string) =
  51. struct
  52.   type v = Vertex.t
  53.   type label = string
  54.   type t = v * v * label
  55.  
  56.   let fst (x, _, _) = x
  57.   let snd (_, x, _) = x
  58.   let trd (_, _, x) = x
  59.  
  60.   let equal e1 e2 = ((fst e1) = (fst e2)) && ((snd e1) = (snd e2)) && ((trd e1) = (trd e2))
  61.   let create v1 v2 l = v1, v2, l
  62.   let label e = trd e
  63.   let in_v e = fst e
  64.   let out_v e = snd e
  65.  
  66. end
  67.  
  68. module Edge = AbstractEdge(Vertex)
Add Comment
Please, Sign In to add comment