-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.hs
More file actions
28 lines (23 loc) · 766 Bytes
/
Main.hs
File metadata and controls
28 lines (23 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Main where
import Control.Monad
import Data.Either
import Parser (parseInput, expr)
import Interp (Sentence, Expr, Atom, interpret)
import Trans (translate) --(reduceGraph)
main =
fmap (\x -> leftToStr (parseInput x) >>= interpret >>= return . translate) getLines
>>= outputStr
outputStr :: Either String String -> IO ()
outputStr (Left err) = putStrLn err
outputStr (Right a) = putStrLn a
output :: Show a => Either String a -> IO ()
output (Left err) = putStrLn err
output (Right a) = print a
leftToStr :: Show e => Either e a -> Either String a
leftToStr (Left err) = Left $ show err
leftToStr (Right x) = Right x
getLines :: IO String
getLines = getLine >>= next
where
next "" = return ""
next s = liftM ((s ++ "\n") ++) getLines