{-# LANGUAGE FlexibleContexts #-} module Task09 where import Control.Applicative import Control.Monad.Reader import Data.Map.Strict ( Map ) import qualified Data.Map.Strict as Map type Varname = String data AExpr = Con Integer | Var Varname | Add AExpr AExpr | Mul AExpr AExpr deriving ( Eq, Show, Read ) type Assignment = Map Varname Integer value :: MonadReader Assignment m => String -> m Integer value v = reader (Map.findWithDefault 0 v) evala :: MonadReader Assignment m => AExpr -> m Integer evala (Con x) = pure x evala (Var x) = value x evala (Add x y) = liftA2 (+) (evala x) (evala y) evala (Mul x y) = liftA2 (*) (evala x) (evala y) data BExpr = Equal AExpr AExpr | LEQ AExpr AExpr | And BExpr BExpr | Not BExpr deriving ( Eq, Show, Read ) evalb :: _ evalb = undefined data LAExpr = LCon Integer | LVar Varname | LAdd LAExpr LAExpr | LMul LAExpr LAExpr | Let Varname LAExpr LAExpr deriving ( Eq, Show, Read ) evalla :: _ evalla = undefined