From 1ed4222009881d320de99275c369c4f55ef56237 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Mon, 18 Jun 2018 17:00:11 +0200 Subject: [PATCH] sep of concerns --- expr/exist/while.dcl | 12 +++++++++--- expr/exist/while.icl | 24 ++++++++++++++++++++++++ expr/exist/whileMult.dcl | 1 + expr/exist/whileMult.icl | 1 + expr/exist/whileRep.dcl | 1 + expr/exist/whileRep.icl | 4 +++- 6 files changed, 39 insertions(+), 4 deletions(-) diff --git a/expr/exist/while.dcl b/expr/exist/while.dcl index 7431e3f..a2535f3 100644 --- a/expr/exist/while.dcl +++ b/expr/exist/while.dcl @@ -9,20 +9,20 @@ definition module while | (:.) infixr 0 WhileExpr WhileExpr | While WhileBool Do WhileExpr | Skip - | E.e: WExpr e & eval e + | E.e: WExpr e & eval e & print e :: WhileBool = Bool Bool | (==.) infix 4 WhileInt WhileInt | (&.) infix 3 WhileBool WhileBool | Not WhileBool - | E.e: WBool e & evalb e + | E.e: WBool e & evalb e & print e :: WhileInt = Int Int | Var String | (+.) infixl 6 WhileInt WhileInt - | E.e: WInt e & evali e + | E.e: WInt e & evali e & print e class gamma g where @@ -40,3 +40,9 @@ class evalb m :: m -> (g -> Bool) | gamma g instance eval WhileExpr instance evali WhileInt instance evalb WhileBool + +class print m :: m -> String + +instance print WhileExpr +instance print WhileInt +instance print WhileBool diff --git a/expr/exist/while.icl b/expr/exist/while.icl index 4e23327..72430fc 100644 --- a/expr/exist/while.icl +++ b/expr/exist/while.icl @@ -35,4 +35,28 @@ where evalb (Not a) = not o evalb a evalb (WBool e) = evalb e +instance print WhileExpr +where + print (i =. v) = i +++ " := " +++ print v + print (If b _ t _ e) = "If " +++ print b +++ " then " +++ print t +++ " else " +++ print e + print (a :. b) = print a +++ "; " +++ print b + print x=:(While b _ e) = "While " +++ print b +++ " do " +++ print e + print Skip = "Skip" + print (WExpr e) = print e + +instance print WhileInt +where + print (Int i) = toString i + print (Var s) = s + print (a +. b) = print a +++ " + " +++ print b + print (WInt e) = print e + +instance print WhileBool +where + print (Bool b) = toString b + print (a ==. b) = print a +++ " = " +++ print b + print (a &. b) = print a +++ " && " +++ print b + print (Not a) = "!" +++ print a + print (WBool e) = print e + Start = (eval ("a" =. Int 42 :. While (Bool False) Do ("b" =. Int 4)) emptyGamma) "a" diff --git a/expr/exist/whileMult.dcl b/expr/exist/whileMult.dcl index 6179bf5..4a8b991 100644 --- a/expr/exist/whileMult.dcl +++ b/expr/exist/whileMult.dcl @@ -8,3 +8,4 @@ import while (*.) a b :== WInt (WMult a b) instance evali WMult +instance print WMult diff --git a/expr/exist/whileMult.icl b/expr/exist/whileMult.icl index 379404e..a7e6283 100644 --- a/expr/exist/whileMult.icl +++ b/expr/exist/whileMult.icl @@ -4,3 +4,4 @@ import StdEnv import while instance evali WMult where evali (WMult a b) = \g->evali a g * evali b g +instance print WMult where print (WMult a b) = print a +++ " * " +++ print b diff --git a/expr/exist/whileRep.dcl b/expr/exist/whileRep.dcl index 2fdea00..dd16bf8 100644 --- a/expr/exist/whileRep.dcl +++ b/expr/exist/whileRep.dcl @@ -8,3 +8,4 @@ import while Repeat e Until b :== WExpr (WRepeat e Until b) instance eval WRep +instance print WRep diff --git a/expr/exist/whileRep.icl b/expr/exist/whileRep.icl index 6b5fe6f..da70d5e 100644 --- a/expr/exist/whileRep.icl +++ b/expr/exist/whileRep.icl @@ -1,7 +1,9 @@ implementation module whileRep +import StdEnv import while :: WRep = WRepeat WhileExpr Until WhileBool -instance eval WRep where eval (WRepeat e Until b) = eval (e :. While b Do e) +instance eval WRep where eval (WRepeat e _ b) = eval (e :. While b Do e) +instance print WRep where print (WRepeat e _ b) = "Repeat " +++ print e +++ " until " +++ print b -- 2.20.1