[SOLVED] CS代写 module Common where

30 $

File Name: CS代写_module_Common_where.zip
File Size: 263.76 KB

SKU: 7395219663 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


module Common where

import Prelude hiding (LT, GT, EQ)

Copyright By PowCoder代写加微信 assignmentchef

type Label = String
type Var = String

data BinaryOp = Add | Sub | Mult | Div | And | Or
| GT| LT| LE | GE| EQ
| Index | Append | Remove
deriving Eq

instance Show BinaryOp where
show Add= “+”
show Sub= “-”
show Mult = “*”
show Div= “/”
show And= “&&”
show Or = “||”
show GT = “>”
show LT = “<“show LE = “<=”show GE = “>=”
show EQ = “==”
show Index= “!!”
show Append = “++”
show Remove = “\\”

data UnaryOp = Neg | Not | Length | Null
deriving Eq

instance Show UnaryOp where
show Neg= “-”
show Not= “!”
show Length = “#”
show Null = “?”

showMethod :: Show m => (Label, m) -> String
showMethod (l, m) = show l ++ “: ” ++ show m

data Value = IntV Int
| BoolV Bool
| StringV String
| ObjRef Int
deriving Eq

instance Show Value where
show (IntV i)= show i
show (BoolV b) = show b
show (StringV s) = show s
show (ObjRef i)= ++ show i

unary :: UnaryOp -> Value -> Value
unary Not (BoolV b) = BoolV (not b)
unary Neg (IntV i)= IntV (-i)
unary _ _ = error “TODO: Question 3”

binary :: BinaryOp -> Value -> Value -> Value
binary Add(IntV a)(IntV b)= IntV (a + b)
binary Sub(IntV a)(IntV b)= IntV (a – b)
binary Mult (IntV a)(IntV b)= IntV (a * b)
binary Div(IntV a)(IntV b)= IntV (a `div` b)
binary And(BoolV a) (BoolV b) = BoolV (a && b)
binary Or (BoolV a) (BoolV b) = BoolV (a || b)
binary LT (IntV a)(IntV b)= BoolV (a < b)binary LE (IntV a)(IntV b)= BoolV (a <= b)binary GE (IntV a)(IntV b)= BoolV (a >= b)
binary GT (IntV a)(IntV b)= BoolV (a > b)
binary EQ a b = BoolV (a == b)
binary _ _ _ = error “TODO: Question 3”

程序代写 CS代考加微信: assignmentchef QQ: 1823890830 Email: [email protected]

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS代写 module Common where
30 $