代写代考 module Types where

module Types where

import Prelude hiding (log)
import Control.Exception

Copyright By PowCoder代写 加微信 powcoder

data Error = Error {errMsg :: String}
deriving (Show)

instance Exception Error

data Binop
deriving (Eq, Show)

type Id = String

— | Expressions
= EInt Int
| EBin Binop
| ELog String Expr
deriving (Eq, Show)

— | Values
data Value
= VInt Int
| VThunk Env Expr
| VErr String
deriving (Eq, Show)

type Env = [(Id, Value)]

— | Look up an identifier in the environment
lookupId :: Id -> Env -> Value
lookupId x ((y, v) : env)
| x == y = v
| otherwise = lookupId x env
lookupId x [] = throw (Error (“unbound variable: ” ++ x))

— | Extend an environment with a new binding
extend :: Id -> Value -> Env -> Env
extend x v env = (x, v) : env

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com