diff src/multimap_fn.sml @ 2203:39faa4a037f4

ML half of initial prototype. (Doesn't compile because there's no C yet.)
author Ziv Scully <ziv@mit.edu>
date Tue, 25 Mar 2014 02:04:06 -0400
parents
children 365727ff68f4
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/multimap_fn.sml	Tue Mar 25 02:04:06 2014 -0400
@@ -0,0 +1,14 @@
+functor MultimapFn (structure KeyMap : ORD_MAP structure ValSet : ORD_SET) = struct
+    type key = KeyMap.Key.ord_key
+    type item = ValSet.item
+    type items = ValSet.set
+    type multimap = ValSet.set KeyMap.map
+    fun inserts (kToVs : multimap, k : key, vs : items) : multimap =
+        KeyMap.unionWith ValSet.union (kToVs, KeyMap.singleton (k, vs))
+    fun insert (kToVs : multimap, k : key, v : item) : multimap =
+        inserts (kToVs, k, ValSet.singleton v)
+    fun find (kToVs : multimap, k : key) =
+        case KeyMap.find (kToVs, k) of
+            SOME vs => vs
+          | NONE => ValSet.empty
+end