summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/src
diff options
context:
space:
mode:
Diffstat (limited to 'lambda-calcul/haskell/src')
-rw-r--r--lambda-calcul/haskell/src/Minilang/REPL/Haskeline.hs2
-rw-r--r--lambda-calcul/haskell/src/Minilang/REPL/IO.hs3
-rw-r--r--lambda-calcul/haskell/src/Minilang/REPL/Pure.hs11
3 files changed, 12 insertions, 4 deletions
diff --git a/lambda-calcul/haskell/src/Minilang/REPL/Haskeline.hs b/lambda-calcul/haskell/src/Minilang/REPL/Haskeline.hs
index a822116..cbc7988 100644
--- a/lambda-calcul/haskell/src/Minilang/REPL/Haskeline.hs
+++ b/lambda-calcul/haskell/src/Minilang/REPL/Haskeline.hs
@@ -83,7 +83,7 @@ completion' (inputString, _) =
]
completeLoadWithFiles prefix = do
- files <- filter (prefix `isPrefixOf`) . filter (".mtt" `isSuffixOf`) <$> listDirectory "."
+ files <- filter (prefix `isPrefixOf`) . filter (".lisp" `isSuffixOf`) <$> listDirectory "."
pure ("", fmap (\fp -> Completion (":load " <> fp) fp True) files)
setUnsetCompletion com =
diff --git a/lambda-calcul/haskell/src/Minilang/REPL/IO.hs b/lambda-calcul/haskell/src/Minilang/REPL/IO.hs
index 90b1e5d..ad6d52b 100644
--- a/lambda-calcul/haskell/src/Minilang/REPL/IO.hs
+++ b/lambda-calcul/haskell/src/Minilang/REPL/IO.hs
@@ -11,6 +11,7 @@ import Data.Text.IO as Text
import Minilang.REPL.Types
import System.IO (Handle, hFlush)
import System.IO.Error (isEOFError)
+import Minilang.REPL.Pure (render)
data IOEnv = IOEnv
{ inputHandle :: Handle,
@@ -23,7 +24,7 @@ newtype CONSOLE m a = CONSOLE {runConsole :: StateT IOEnv m a}
instance MonadREPL (CONSOLE IO) where
input = get >>= lift . (\h -> (interpret <$> hGetLine h) `catch` \(isEOFError -> True) -> pure EOF) . inputHandle
- output a = get >>= lift . flip hPutStrLn (pack $ show a) . outputHandle
+ output a = get >>= lift . flip hPutStrLn (render a) . outputHandle
prompt = get >>= lift . (\h -> hPutStr h "λΠ> " >> hFlush h) . outputHandle
getEnv = get >>= pure . repl
setEnv e' = modify $ \e -> e {repl = e'}
diff --git a/lambda-calcul/haskell/src/Minilang/REPL/Pure.hs b/lambda-calcul/haskell/src/Minilang/REPL/Pure.hs
index 23c45e1..91e71b9 100644
--- a/lambda-calcul/haskell/src/Minilang/REPL/Pure.hs
+++ b/lambda-calcul/haskell/src/Minilang/REPL/Pure.hs
@@ -8,6 +8,8 @@ import Control.Monad.Catch
import Control.Monad.Catch.Pure (CatchT (..))
import Control.Monad.State
import Data.Text hiding (replicate)
+import Minilang.Lambda.Parser (pretty, resugar)
+import qualified Minilang.Lambda.Unify as Type
import Minilang.REPL.Types
data PureEnv = PureEnv
@@ -21,20 +23,25 @@ newtype PureREPL a = PureREPL {runPure :: CatchT (State PureEnv) a}
instance MonadREPL PureREPL where
input = do
- ins <- inputText <$> get
+ ins <- gets inputText
case ins of
[] -> pure EOF
(t : ts) -> modify (\e -> e {inputText = ts}) >> pure (interpret t)
output t = modify $ \e -> e {outputText = render t : outputText e}
+
prompt = pure ()
- getEnv = get >>= pure . pureREPL
+
+ getEnv = gets pureREPL
+
setEnv e' = modify $ \e -> e {pureREPL = e'}
+
load f = pure $ Left $ REPLError $ "cannot load file " <> f <> " in Pure interpreter"
render :: Out -> Text
render = \case
Msg t -> t
+ Evaluated term typ -> pretty (resugar term) <> " : " <> Type.pretty typ
Bye -> "Bye!"
other -> pack (show other)