summaryrefslogtreecommitdiff
path: root/fp2/week45/mart
diff options
context:
space:
mode:
Diffstat (limited to 'fp2/week45/mart')
-rw-r--r--fp2/week45/mart/RefactorX.dcl17
-rw-r--r--fp2/week45/mart/RefactorX.icl72
2 files changed, 0 insertions, 89 deletions
diff --git a/fp2/week45/mart/RefactorX.dcl b/fp2/week45/mart/RefactorX.dcl
deleted file mode 100644
index 393c097..0000000
--- a/fp2/week45/mart/RefactorX.dcl
+++ /dev/null
@@ -1,17 +0,0 @@
-// Mart Lubbers s4109503, Camil Staps s4498062
-
-definition module RefactorX
-
-from StdClass import class toString
-import StdEnv
-
-:: Expr = NR Int | VAR Name | OP Expr Operator Expr | LET Name Expr Expr
-:: Name :== String
-:: Operator = PLUS | MIN | MUL | DIV
-:: Val = Result Int | Undef
-
-
-instance toString Expr
-free :: Expr -> [Name]
-remove_unused_lets :: Expr -> Expr
-eval :: Expr -> Val
diff --git a/fp2/week45/mart/RefactorX.icl b/fp2/week45/mart/RefactorX.icl
deleted file mode 100644
index c74df08..0000000
--- a/fp2/week45/mart/RefactorX.icl
+++ /dev/null
@@ -1,72 +0,0 @@
-// Mart Lubbers s4109503, Camil Staps s4498062
-
-implementation module RefactorX
-
-import StdEnv
-
-//Start = map toString [E1,E2,E3,E4,E5]
-//Start = map free [E1,E2,E3,E4,E5]
-//Start = map toString (map remove_unused_lets [E1,E2,E3,E4,E5])
-Start = map eval [E1,E2,E3,E4,E5]
- where
- E1 = OP (LET "x" (OP (NR 42) MIN (NR 3)) (OP (VAR "x") DIV (NR 0))) PLUS (LET "y" (NR 6) (OP (VAR "y") MUL (VAR "y")))
- E2 = LET "x" (NR 42) (OP (VAR "x") PLUS (LET "x" (NR 58) (VAR "x")))
- E3 = LET "x" (NR 1) (LET "y" (NR 2) (LET "x" (NR 3) (NR 4)))
- E4 = LET "x" (NR 1) (OP (VAR "x") PLUS (VAR "y"))
- E5 = OP (LET "x" (NR 1) (VAR "x")) MUL (VAR "x")
-
-(<+) infixl 9 :: String a -> String | toString a
-(<+) str a = str +++ toString a
-
-instance toString Operator where
- toString PLUS = "+"
- toString MIN = "-"
- toString MUL = "*"
- toString DIV = "/"
-
-instance toString Expr where
- toString (NR n) = toString n
- toString (VAR v) = v
- toString (LET n e1 e2) = "(let " <+ n <+ "=" <+ e1 <+ " in " <+ e2 <+ ")"
- toString (OP e1 o e2) = bracket e1 <+ o <+ bracket e2
- where
- bracket :: Expr -> String
- bracket (OP e1 o e2) = "(" <+ (OP e1 o e2) <+ ")"
- bracket e = toString e
-
-free:: Expr -> [Name]
-free (NR n) = []
-free (VAR v) = [v]
-free (OP e1 o e2) = removeDup (free e1 ++ free e2)
-free (LET n e1 e2) = removeMember n (free e2)
-
-remove_unused_lets:: Expr -> Expr
-remove_unused_lets (LET n e1 e2)
-| isMember n (free e2) = (LET n (remove_unused_lets e1) (remove_unused_lets e2))
-| otherwise = remove_unused_lets e2
-remove_unused_lets (OP e1 o e2) = (OP (remove_unused_lets e1) o (remove_unused_lets e2))
-remove_unused_lets e = e
-
-apply:: Operator Val Val -> Val
-apply _ Undef _ = Undef
-apply _ _ Undef = Undef
-apply DIV _ (Result 0) = Undef
-apply o (Result e1) (Result e2) = Result (apply` o e1 e2)
- where
- apply`:: Operator -> Int Int -> Int
- apply` PLUS = +
- apply` MIN = -
- apply` MUL = *
- apply` DIV = /
-
-eval:: Expr -> Val
-eval e = eval` e []
- where
- eval`:: Expr [(Name, Val)] -> Val
- eval` (NR n) _ = Result n
- eval` (VAR v) [] = Undef
- eval` (VAR v) [(n, e):xs]
- | v == n = e
- | otherwise = eval` (VAR v) xs
- eval` (OP e1 o e2) xs = apply o (eval` e1 xs) (eval` e2 xs)
- eval` (LET n e1 e2) xs = eval` e2 [(n, eval` e1 xs):xs]