Improved variable definition error messages
This commit is contained in:
parent
d3f63b1d15
commit
5bc54cd13a
1 changed files with 5 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue