0

How can i change a variable during runtime?

I got this:

data Ausdruck = K Wahrheitswert                 -- Logical constant
                | V Variable                    -- Logical Variable
                | Nicht Ausdruck                -- Logical negation
                | Und Ausdruck Ausdruck         -- Logical and
                | Oder Ausdruck Ausdruck        -- Logical or
                | Impl Ausdruck Ausdruck        -- Logical implied
                | Esgibt Variable Ausdruck      -- "exist"
                | Fueralle Variable Ausdruck    -- "all"
                                    deriving (Eq,Show)



type Variables = Variable -> Bool

    variables1 :: Variable -> Bool
    variables1 (Var N1) = True
    variables1 (Var N2) = False
    variables1 (Var N3) = True
    variables1 (Var N4) = True
    variables1 (Var N5) = False




evaluate :: Prop -> Variables -> Bool
evaluate (K bool) belegung = bool
evaluate (V var) belegung = belegung var
evaluate (Nicht ausdruck) belegung = not (evaluate ausdruck belegung)
evaluate (Und ausdruck ausdruck2) belegung = (evaluate ausdruck belegung) && (evaluate ausdruck2 belegung)
evaluate (Oder ausdruck ausdruck2) belegung = (evaluate ausdruck belegung) || (evaluate ausdruck2 belegung)

Now i want to add the quantifier "all". So i want to check an Propositional calculus if its still true, when i change N1 to False. But how can i change a variable during runtime?

Best regards Marc

3
  • Do I understand correctly that you want to provide some user input that changes the state of the program such that variables1 (Var N1) = False? Commented Nov 27, 2017 at 15:00
  • 1
    evaluate is already parameterized; you just pass a function other than variables1 as its second argument. Commented Nov 27, 2017 at 15:12
  • Btw, Füralle is a perfectly legitimate constructor name. Commented Nov 28, 2017 at 17:45

1 Answer 1

1

You can create a new environment based on an existing environment with a variable bound to a new value:

erweiternBelegung :: Variable -> Bool -> Variables -> Variables
erweiternBelegung v b vs = \v' -> if v == v' then b else vs v'

and use it to make sure that, in the Fueralle case, ausdruck holds when var is both True and False:

...
evaluate (Fueralle var ausdruk) belegung =
  evaluate ausdruk (erweiternBelegung var True belegung) &&
  evaluate ausdruk (erweiternBelegung var False belegung)

The existential quantifier Esgibt will be the same, except the && will be replaced with ||.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.