aboutsummaryrefslogtreecommitdiffstats
path: root/src/MyLib.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/MyLib.hs')
-rw-r--r--src/MyLib.hs15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/MyLib.hs b/src/MyLib.hs
index 6539412..864f99e 100644
--- a/src/MyLib.hs
+++ b/src/MyLib.hs
@@ -1,13 +1,10 @@
-module MyLib (someFunc) where
+module BizExpr (repl, eval) where
import Data.Maybe (fromMaybe)
import Text.Read (readMaybe)
--import Data.Text as T
-someFunc :: IO ()
-someFunc = putStrLn "someFunc"
-
repl :: IO ()
repl = getLine >>= putStrLn . maybe "Failed to evaluate expression" show . eval >> repl
@@ -30,11 +27,17 @@ instance CoerceTo Integer where
coerceFrom = IntVal
instance CoerceTo Bool where
+ coerceTo (BoolVal v) = Just v
coerceTo (IntVal v) = Just $ v /= 0
coerceTo (StrVal "True") = Just True
coerceTo (StrVal "true") = Just True
- coerceTo (BoolVal v) = Just v
- coerceTo _ = Just False
+ --coerceTo v@(StrVal _) = coerceTo . IntVal =<< (coerceTo v :: Maybe Integer) :: Maybe Bool
+ coerceTo v@(StrVal x) = case (readMaybe x :: Maybe Integer) of
+ Nothing -> Just False
+ Just n -> Just $ True--n /= 0
+-- case coerceTo v :: Maybe Integer of
+-- Nothing -> Just False
+-- Just n -> coerceTo (IntVal n)
coerceFrom = BoolVal