Error out for undefined variables
This commit is contained in:
parent
16aca9a66b
commit
9e7ad28c5c
2 changed files with 17 additions and 8 deletions
|
@ -2,7 +2,7 @@ module Main (main) where
|
|||
|
||||
import Text.Parsec
|
||||
|
||||
import Lib (exprparser, evaluate, replaceVars)
|
||||
import Lib (exprparser, evaluate, replaceVars, Expr)
|
||||
|
||||
import Data.Map (Map)
|
||||
import qualified Data.Map as Map
|
||||
|
@ -21,8 +21,9 @@ showRatio p r = (if (r < 0) then "-" else "") ++ prepoint_digits ++ (if (length
|
|||
prepoint_digits = init . show . round . abs $ (r * 10)
|
||||
postpoint_digits = reverse .dropWhile (=='0') . reverse .(take p) . (drop (length prepoint_digits)) . show . round . abs $ (r * 10^p)
|
||||
|
||||
useResult (Right e) = (showRatio precision) . evaluate $ replaceVars e vars
|
||||
useResult (Left e) = show e
|
||||
useResult :: Either ParseError Expr -> String
|
||||
useResult (Right expr) = either id ((showRatio precision) . evaluate) $ replaceVars expr vars
|
||||
useResult (Left error) = show error
|
||||
|
||||
vars :: Map String Rational
|
||||
vars = Map.fromList [("pi", 245850922 % 78256779), ("e", 271801 % 99990)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue