data Digit = D0 | D1 | D2 | D3 | D4 | D5 | D6 | D7 | D8 | D9 

data Num = D Digit | Num :> Digit

digit :: Digit -> Integer
digit D0 = 0
digit D1 = 1
digit D2 = 2
digit D3 = 3
digit D9 = 9

num :: Num -> Integer 
num (D d) = digit d
num (n :> d) = 10 * num n + digit d

type Var = String

type State = Var -> Integer

update :: Var -> Integer -> State -> State
update x z s = \ y -> if x == y then z else s y

init :: State
init _ = 0

data AExp = N Num | V Var | AExp :+ AExp | AExp :- AExp | AExp :* AExp

aexp :: AExp -> State -> Integer
aexp (N n) _      = num n
aexp (V x) s      = s x
aexp (a0 :+ a1) s = aexp a0 s + aexp a1 s
aexp (a0 :- a1) s = aexp a0 s - aexp a1 s
aexp (a0 :* a1) s = aexp a0 s * aexp a1 s



