aboutsummaryrefslogtreecommitdiffstats
path: root/src/MyLib.hs
diff options
context:
space:
mode:
authordan <[email protected]>2021-04-15 08:09:59 +0200
committerdan <[email protected]>2021-04-15 08:09:59 +0200
commita26253c1efe45459b46edd4d06a4ee03d99eb6dd (patch)
treeea1981ab308b24ed85317c556b53f6ce09a72d0c /src/MyLib.hs
parent638e8ff79ab25db779fa272d61767ab49ac8d751 (diff)
downloadbizexp-a26253c1efe45459b46edd4d06a4ee03d99eb6dd.tar.gz
bizexp-a26253c1efe45459b46edd4d06a4ee03d99eb6dd.tar.bz2
bizexp-a26253c1efe45459b46edd4d06a4ee03d99eb6dd.zip
(coerceTo $ StrVal 1) ::Maybe Bool -- still doesn't work
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