import "Prelude" as Prelude import "MMap" as MMap import "MList" as MList type T a b = MMap.T a (MList.T b) add :: MMap.T a (MList.T b) -> a -> b -> () add m k v = match MMap.get m k with Just l -> MList.add l v Nothing -> Prelude.ignore (MMap.put m k (MList.singleton v)) get :: MMap.T a (MList.T b) -> a -> [b] get m k = match MMap.get m k with Just l -> MList.freeze l Nothing -> [] indexBy :: (v -> k) -> [v] -> MMap.T k (MList.T v) indexBy f l = do result = MMap.createC (Prelude.length l) Prelude.iter (\v -> add result (f v) v) l result