| 1 |
(* |
| 2 |
* This module implements some combinators that joins two graphs |
| 3 |
* into a single view. |
| 4 |
* |
| 5 |
*) |
| 6 |
|
| 7 |
structure GraphCombinations : GRAPH_COMBINATIONS = |
| 8 |
struct |
| 9 |
|
| 10 |
structure G = Graph |
| 11 |
structure Union = UnionGraphView |
| 12 |
structure Rename = RenamedGraphView |
| 13 |
structure Rev = ReversedGraphView |
| 14 |
|
| 15 |
(* |
| 16 |
* Disjoint union |
| 17 |
*) |
| 18 |
fun my_union (a,b) = Union.union_view (fn (x,y) => x) (a, b) |
| 19 |
fun sum (A as G.GRAPH a, B as G.GRAPH b) = |
| 20 |
my_union(A, Rename.rename_view (#capacity a ()) B) |
| 21 |
fun union [] = raise G.Graph "union" |
| 22 |
| union [a] = a |
| 23 |
| union [a,b] = my_union(a,b) |
| 24 |
| union (a::b) = my_union(a,union b) |
| 25 |
|
| 26 |
fun sums [] = raise G.Graph "sums" |
| 27 |
| sums [a] = a |
| 28 |
| sums [a,b] = sum(a,b) |
| 29 |
| sums (a::b) = sum(a,sums b) |
| 30 |
|
| 31 |
end |
| 32 |
|