-- Evaluate expressions made of additions and good and bad bits. -- Sergio Antoy and Michael Hanus -- Thu Mar 3 16:27:55 PST 2011 -- updated Thu Jun 29 14:37:06 PDT 2017 -- Execute with: curry check this-file import Test.EasyCheck -- 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 -- function value "returns" two items: a Bit and a Boolean -- The Boolean is the ordinary returned value, -- the Bit is the second argument of a call, bound to a free variable value (Add x y) (add vx vy) = value x vx && value y vy value (Good x) x = True value (Bad x) x = False -- We must check the value of 'x' possibly instantiated by the call -- to 'value' only if and after the call successfully completes test30 = let x free y = value (Add (Good One) (Good One)) x in y == True &> x -=- Zero test40 = let x free y = value (Add (Good One) (Bad One)) x in y == False &> x -=- Zero test50 = let x free y = value (Add (Good One) (Add (Good One) (Good One))) x in y == True &> x -=- One