5 | XorF (Formula a) (Formula a)
6 | AndF (Formula a) (Formula a)
9 | UntilF (Formula a) (Formula a)
11 deriving instance (Ord a) => Ord (Formula a)
13 instance (Show a) => Show (Formula a) where
14 sb <+ TrueF = sb << "true"
15 sb <+ FalseF = sb << "false"
16 sb <+ XorF a b = sb << "(" <+ a << " `XorF` " <+ b << ")"
17 sb <+ AndF a b = sb << "(" <+ a << " &&& " <+ b << ")"
18 sb <+ ConditionF c = sb <+ c
19 sb <+ NextF a = sb << "(next " <+ a << ")"
20 sb <+ UntilF a b = sb << "(" <+ a << " `UntilF` " <+ b << ")"
24 xorF f1@(XorF h1 t1) f2@(XorF h2 t2) =
25 let cmp = compare h1 h2
27 then XorF h1 (xorF t1 f2)
29 then XorF h2 (xorF f1 t2)
31 xorF f1@(XorF h1 t1) f2 =
32 let cmp = compare h1 f2
34 then XorF h1 (xorF t1 f2)
38 xorF f1 f2@(XorF h2 t2) =
39 let cmp = compare f1 h2
43 then XorF h2 (xorF f1 t2)
46 let cmp = compare f1 f2
59 XorF h1 t1 &&& f2 = xorF (h1 &&& f2) (t1 &&& f2)
60 f1 &&& XorF h2 t2 = xorF (f1 &&& h2) (f1 &&& t2)
61 f1@(AndF h1 t1) &&& f2@(AndF h2 t2) =
62 let cmp = compare h1 h2
64 then AndF h1 (t1 &&& f2)
66 then AndF h2 (f1 &&& t2)
67 else AndF h1 (t1 &&& t2)
68 f1@(AndF h1 t1) &&& f2 =
69 let cmp = compare h1 f2
71 then AndF h1 (t1 &&& f2)
75 f1 &&& f2@(AndF h2 t2) =
76 let cmp = compare f1 h2
80 then AndF h2 (f1 &&& t2)
83 let cmp = compare f1 f2
90 f1 ||| f2 = xorF (xorF f1 f2) (f1 &&& f2)
92 eval :: Ord a => (a -> <e> Boolean) -> Formula a -> <e> Formula a
94 eval s FalseF = FalseF
95 eval s (XorF f1 f2) = xorF (eval s f1) (eval s f2)
96 eval s (AndF f1 f2) = eval s f1 &&& eval s f2
97 eval s (ConditionF c) = if s c then TrueF else FalseF
99 eval s (UntilF f1 f2) = eval s f2 ||| (eval s f1 &&& UntilF f1 f2)
101 // Concrete conditions
103 data V = V String (Ref Boolean)
106 compare (V a _) (V b _) = compare a b
107 instance Show V where
108 sb <+ V a _ = sb <+ a
110 cond :: String -> Ref Boolean -> Formula V
111 cond name ref = ConditionF (V name ref)
118 f = cond "x" x `UntilF` cond "y" y
120 evalV = eval (\(V _ c) -> getRef c)