From e8e86cea2bffe23961f0a1bea8ee770343894858 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 9 Apr 2020 20:09:43 +0200 Subject: builtin cleaning --- src/Evaluation.hs | 52 ++++------------------------------------------------ 1 file changed, 4 insertions(+), 48 deletions(-) (limited to 'src/Evaluation.hs') diff --git a/src/Evaluation.hs b/src/Evaluation.hs index b0b5aab..f0db71c 100644 --- a/src/Evaluation.hs +++ b/src/Evaluation.hs @@ -3,14 +3,13 @@ module Evaluation where import Expr import qualified Assignment as A -eval :: A.Context -> Expr -> Maybe Atom +eval :: A.Context -> Expr -> Maybe Expr eval c (Variable n) = do (A.Variable _ e) <- A.get c n eval c e eval c (Function n e) = do x <- eval c e (A.Function _ param fe) <- A.get c n - let tmp = A.update c (A.Variable param (EAtom x)) + let tmp = A.update c (A.Variable param x) eval tmp fe -eval c (EAtom a) = Just a eval c (Add e1 e2) = evalInfix c e1 e2 (+?) eval c (Sub e1 e2) = evalInfix c e1 e2 (-?) eval c (Mul e1 e2) = evalInfix c e1 e2 (*?) @@ -18,52 +17,9 @@ eval c (Div e1 e2) = evalInfix c e1 e2 (/?) eval c (Mod e1 e2) = evalInfix c e1 e2 (%?) eval c (Exp e1 e2) = evalInfix c e1 e2 (^?) eval c (Dot e1 e2) = evalInfix c e1 e2 (**?) --- eval _ _ = Nothing +eval c x = Just x -evalInfix :: A.Context -> Expr -> Expr -> (Atom -> Atom -> Maybe Atom) -> Maybe Atom +evalInfix :: A.Context -> Expr -> Expr -> (Expr -> Expr -> Maybe Expr) -> Maybe Expr evalInfix c e1 e2 f = do a <- eval c e1 b <- eval c e2 f a b - -infixl 6 +? -(+?) :: Atom -> Atom -> Maybe Atom -(Rational a) +? (Rational b) = Just $ Rational (a + b) -(Imaginary a) +? (Imaginary b) = Just $ Imaginary (a + b) -_ +? _ = Nothing - -infixl 6 -? -(-?) :: Atom -> Atom -> Maybe Atom -(Rational a) -? (Rational b) = Just $ Rational (a - b) -(Imaginary a) -? (Imaginary b) = Just $ Imaginary (a - b) -_ -? _ = Nothing - -infixl 7 *? -(*?) :: Atom -> Atom -> Maybe Atom -(Rational a) *? (Rational b) = Just $ Rational (a * b) -(Rational a) *? (Imaginary b) = Just $ Imaginary (a * b) -(Imaginary a) *? (Imaginary b) = (Imaginary (a * b)) ^? Rational 2 -_ *? _ = Nothing - -infixl 7 /? -(/?) :: Atom -> Atom -> Maybe Atom -_ /? (Rational 0) = Nothing -(Rational a) /? (Rational b) = Just $ Rational (a / b) -_ /? _ = Nothing - -infixl 7 %? -(%?) :: Atom -> Atom -> Maybe Atom -_ %? _ = Nothing - -infixr 8 ^? -(^?) :: Atom -> Atom -> Maybe Atom -(Rational a) ^? (Rational b) = Just $ Rational (a ** b) -(Imaginary a) ^? (Rational 0) = Just $ Rational a -(Imaginary a) ^? (Rational 1) = Just $ Imaginary a -(Imaginary a) ^? (Rational 2) = Just $ Rational (-a) -(Imaginary a) ^? (Rational 3) = Just $ Imaginary (-a) -(Imaginary a) ^? (Rational b) = Imaginary a ^? (Rational (b - 4)) -_ ^? _ = Nothing - -infixr 8 **? -(**?) :: Atom -> Atom -> Maybe Atom -_ **? _ = Nothing -- cgit