From 5e0827b17de6dbb00d2e2fdc01597107551f1307 Mon Sep 17 00:00:00 2001 From: hi Date: Thu, 31 Jul 2025 12:21:50 +0000 Subject: [PATCH] dont use Data.Map --- Main.hs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Main.hs b/Main.hs index 64a1aca..859b8c2 100644 --- a/Main.hs +++ b/Main.hs @@ -3,7 +3,6 @@ import Data.Char (isAlphaNum) import Data.Functor (Functor) import Data.List (intercalate) import Data.Maybe (fromJust) -import qualified Data.Map as M import qualified Data.Set as S newtype Parser symbol output = Parser @@ -107,17 +106,17 @@ q :: Statement q = fromJust $ fst <$> runParser stmt "(!a<->((!(p->q)&x)|y))" atoms :: Statement -> S.Set String -atoms (Atom string) = S.singleton string +atoms (Atom key) = S.singleton key atoms (Not s) = atoms s atoms (And s1 s2) = S.union (atoms s1) (atoms s2) atoms (Or s1 s2) = S.union (atoms s1) (atoms s2) atoms (Implies s1 s2) = S.union (atoms s1) (atoms s2) atoms (Iff s1 s2) = S.union (atoms s1) (atoms s2) -eval :: M.Map String Bool -> Statement -> Maybe Bool +eval :: [(String, Bool)] -> Statement -> Maybe Bool eval assignments = aux where - aux (Atom string) = M.lookup string assignments + aux (Atom key) = lookup key assignments aux (Not s) = not <$> aux s aux (And s1 s2) = (&&) <$> aux s1 <*> aux s2 aux (Or s1 s2) = (||) <$> aux s1 <*> aux s2 @@ -137,7 +136,7 @@ bucket s | otherwise = Contingent where atomsList = S.toList $ atoms s - values = [fromJust $ eval (M.fromList assignments) s | assignments <- enumerate $ atomsList] + values = [fromJust $ eval assignments s | assignments <- enumerate $ atomsList] enumerate :: [a] -> [[(a, Bool)]] enumerate keys = aux start