diff options
author | Akshay <[email protected]> | 2020-10-17 04:57:40 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2020-10-17 04:57:40 +0100 |
commit | 032e26cf9ed236889637e02e56aef7c22721cd23 (patch) | |
tree | 6a9ae58d7c5a661249d400eb281c7a2c44263eaf /bin | |
parent | 297b498acd205f0fcd68f3cdf7536b480cfac5e3 (diff) |
prefer applicative over monadic style
Diffstat (limited to 'bin')
-rw-r--r-- | bin/Main.hs | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/bin/Main.hs b/bin/Main.hs index c66d328..18e1c53 100644 --- a/bin/Main.hs +++ b/bin/Main.hs | |||
@@ -20,7 +20,7 @@ readExpr inp = | |||
20 | 20 | ||
21 | evalExpr :: Env -> String -> IO (LispResult String) | 21 | evalExpr :: Env -> String -> IO (LispResult String) |
22 | evalExpr env inp = runExceptT $ fmap show $ | 22 | evalExpr env inp = runExceptT $ fmap show $ |
23 | (liftLispResult $ readExpr inp) >>= eval env | 23 | liftLispResult (readExpr inp) >>= eval env |
24 | 24 | ||
25 | repl :: Env -> IO () | 25 | repl :: Env -> IO () |
26 | repl env = do | 26 | repl env = do |
@@ -29,20 +29,17 @@ repl env = do | |||
29 | case inp of | 29 | case inp of |
30 | Nothing -> return () | 30 | Nothing -> return () |
31 | Just ",q" -> return () | 31 | Just ",q" -> return () |
32 | Just i -> do | 32 | Just i -> evalExpr env i >>= either (putStrLn . pp i) putStrLn >> repl env |
33 | out <- evalExpr env i | ||
34 | either (putStrLn . pp i) putStrLn out | ||
35 | repl env | ||
36 | 33 | ||
37 | 34 | ||
38 | main :: IO () | 35 | main :: IO () |
39 | main = do | 36 | main = do |
40 | args <- getArgs | 37 | args <- getArgs |
41 | initEnv <- newEnv | 38 | env <- newEnv |
42 | if null args | 39 | if null args |
43 | then do | 40 | then do |
44 | putStrLn ";;; Entering lisk repl ..." | 41 | putStrLn ";;; Entering lisk repl ..." |
45 | repl initEnv | 42 | repl env |
46 | else do | 43 | else do |
47 | let pp = showError defaults "(lisk-repl)" | 44 | let pp = showError defaults "(lisk-repl)" |
48 | evalExpr initEnv (head args) >>= (either (putStrLn . pp) print) | 45 | evalExpr env (head args) >>= either (putStrLn . pp) print |