-- Evaluate expressions made of additions and good and bad bits. -- Sergio Antoy and Michael Hanus -- Thu Mar 3 16:27:55 PST 2011 -- The value of expressions containing "bad" bits is false. -- The value of expressions containing only "good" bits is true. -- The actual value is returned in the second argument of "value". data Bit = Zero | One data Expr = Add Expr Expr | Good Bit | Bad Bit add Zero x = x add One Zero = One add One One = Zero value (Add x y) (add vx vy) = value x vx && value y vy value (Good x) y | x =:= y = True value (Bad _) _ = False test1 | value (Add (Good One) (Good One)) x = x where x free test2 | value (Add (Good One) (Bad One)) x = x where x free test3 | value (Add (Good One) (Add (Good One) (Good One))) x = x where x free