Organize code into a Lambda module
This commit is contained in:
parent
46d74f73f2
commit
511ab62af5
2 changed files with 54 additions and 50 deletions
26
interactive.hs
Normal file
26
interactive.hs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import qualified Lambda as L
|
||||
import Data.Maybe
|
||||
|
||||
-- Helper type for using arbitrary strings as symbols
|
||||
newtype StrSymbol = StrSymbol String
|
||||
|
||||
instance Show StrSymbol where
|
||||
show (StrSymbol s) = s
|
||||
|
||||
instance Eq StrSymbol where
|
||||
(StrSymbol a) == (StrSymbol b) = a == b
|
||||
|
||||
linewise :: (String -> String) -> String -> String
|
||||
linewise f = unlines . map f . lines
|
||||
|
||||
evaluate :: String -> String
|
||||
evaluate s =
|
||||
let result = return
|
||||
. map (L.display True)
|
||||
. L.evaluate
|
||||
. fmap StrSymbol
|
||||
l = fromMaybe ["Error: Could not parse expression."]
|
||||
$ L.parseMaybe s >>= result
|
||||
in unlines l
|
||||
|
||||
main = interact $ linewise evaluate
|
||||
Loading…
Add table
Add a link
Reference in a new issue