From 533c9950f4c44363622ebc443fa2987cf08b1318 Mon Sep 17 00:00:00 2001 From: Simon Huber Date: Mon, 19 Sep 2016 11:26:00 +0200 Subject: [PATCH] Fix insertSystem to maintain invariant for systems Closes #52. --- Connections.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Connections.hs b/Connections.hs index 077d575..a6196f9 100644 --- a/Connections.hs +++ b/Connections.hs @@ -388,10 +388,10 @@ showSystem :: Show a => System a -> String showSystem = showListSystem . toList insertSystem :: Face -> a -> System a -> System a -insertSystem alpha v ts = case find (comparable alpha) (keys ts) of - Just beta | alpha `leq` beta -> ts - | otherwise -> Map.insert alpha v (Map.delete beta ts) - Nothing -> Map.insert alpha v ts +insertSystem alpha v ts + | any (leq alpha) (keys ts) = ts + | otherwise = Map.insert alpha v + (Map.filterWithKey (\gamma _ -> not (gamma `leq` alpha)) ts) insertsSystem :: [(Face, a)] -> System a -> System a insertsSystem faces us = foldr (uncurry insertSystem) us faces -- 2.34.1