diff --git a/src/Lib.hs b/src/Lib.hs index 837103c..8e9a7e5 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -102,9 +102,9 @@ updateVariables ds vs = foldl updateVariable (Right vs) ds updateVariable :: Either String (Map String Rational) -> (String, Expr) -> Either String (Map String Rational) updateVariable (Left e) _ = Left e updateVariable (Right vs) (name, e) = case updateVariables nvs vs of - Left e -> Left e + Left e -> Left $ "In definition of variable '" ++ name ++ "':\n" ++ e Right uvs -> case replaceVars e uvs of - Left e -> Left e + Left e -> Left $ "In definition of variable '" ++ name ++ "':\n" ++ e Right exp -> Right $ Map.insert name (evaluate exp) uvs where nvs = extractVariableDefinitions e @@ -130,7 +130,9 @@ replaceVars (Binary op l r) vs = case leftBranch of rationalPower :: Rational -> Rational -> Rational rationalPower a b = rationalPower' (numerator a, denominator a) (numerator b, denominator b) where - rationalPower' (a, b) (c, 1) = a ^ c % b ^ c + rationalPower' (a, b) (c, 1) + | c >= 0 = a ^ c % b ^ c + | otherwise = 1 / rationalPower (a % b) (-c % 1) rationalPower' _ _ = error "Powers with unnatural numbers are not supported yet" evaluate :: Expr -> Rational