summaryrefslogtreecommitdiff
path: root/lambda-calcul
diff options
context:
space:
mode:
Diffstat (limited to 'lambda-calcul')
-rw-r--r--lambda-calcul/haskell/src/Minilang/REPL/Run.hs8
-rw-r--r--lambda-calcul/haskell/src/Minilang/REPL/Types.hs2
-rw-r--r--lambda-calcul/haskell/test/Minilang/REPL/NetSpec.hs20
-rw-r--r--lambda-calcul/haskell/test/Minilang/REPLSpec.hs3
4 files changed, 21 insertions, 12 deletions
diff --git a/lambda-calcul/haskell/src/Minilang/REPL/Run.hs b/lambda-calcul/haskell/src/Minilang/REPL/Run.hs
index 2282b46..7dc8e81 100644
--- a/lambda-calcul/haskell/src/Minilang/REPL/Run.hs
+++ b/lambda-calcul/haskell/src/Minilang/REPL/Run.hs
@@ -60,7 +60,7 @@ handleCommand ::
handleCommand ClearEnv = getEnv >>= \e -> setEnv (e {env = newEnv, context = newContext})
handleCommand DumpEnv =
getEnv >>= \REPLEnv {..} ->
- output (CurrentEnv env context)
+ output (CurrentEnv env context language)
handleCommand (Load (File file)) = do
t <- load file
case t of
@@ -69,7 +69,11 @@ handleCommand (Load (File file)) = do
handleCommand (Load (Data prog)) = loadProgramInEnv prog
handleCommand (Set (StepTypeChecker st)) = getEnv >>= \e -> setEnv (e {stepTypeCheck = st})
handleCommand (Set (DebugParser st)) = getEnv >>= \e -> setEnv (e {debugParser = st})
-handleCommand (Set (SelectLanguage lang)) = getEnv >>= \e -> setEnv (e {language = lang})
+handleCommand (Set (SelectLanguage lang)) =
+ trace ("selecting language " ++ show lang) $
+ getEnv >>= \e ->
+ setEnv (e {language = lang})
+ >> output (Msg $ "Language set to " <> pack (show lang))
handleCommand Help =
output (Msg helpText)
diff --git a/lambda-calcul/haskell/src/Minilang/REPL/Types.hs b/lambda-calcul/haskell/src/Minilang/REPL/Types.hs
index 4e19c72..61e92e0 100644
--- a/lambda-calcul/haskell/src/Minilang/REPL/Types.hs
+++ b/lambda-calcul/haskell/src/Minilang/REPL/Types.hs
@@ -77,7 +77,7 @@ data Content
data Out
= Defined Text Term
| Evaluated Term Type
- | CurrentEnv Env Context
+ | CurrentEnv Env Context Language
| Msg Text
| Bye
deriving (Eq, Show, Generic, ToJSON, FromJSON)
diff --git a/lambda-calcul/haskell/test/Minilang/REPL/NetSpec.hs b/lambda-calcul/haskell/test/Minilang/REPL/NetSpec.hs
index 076b073..b8f8b22 100644
--- a/lambda-calcul/haskell/test/Minilang/REPL/NetSpec.hs
+++ b/lambda-calcul/haskell/test/Minilang/REPL/NetSpec.hs
@@ -6,8 +6,9 @@ import Control.Concurrent.STM.TVar
import Control.Exception (bracket)
import Control.Monad (forM)
import Data.Aeson (eitherDecode, encode)
-import Minilang.Lambda.Eval (newEnv)
+import Minilang.Lambda.Eval (Term (..), newEnv)
import Minilang.Lambda.Infer (newContext)
+import Minilang.Lambda.Unify (Type (..))
import Minilang.Log
import Minilang.REPL.Net
import Minilang.REPL.Types
@@ -65,16 +66,19 @@ temporaryFile = bracket newTempFile removeFile
spec :: Spec
spec = around withServer $
describe "MiniLang Network REPL" $ do
- -- it "evaluates definition and returns defined symbol" $ \Server {serverPort} -> do
- -- let inp = [In "Unit : U = Sum(tt)"]
- -- expectedOutput = [Right $ Defined (B "Unit") (U 0)]
- -- res <- runTestClient serverPort ".newenv1" inp
+ it "evaluates expression and returns evaluation result" $ \Server {serverPort} -> do
+ let inp = [In "((lam (x) x) y)"]
+ expectedOutput = [Right $ Evaluated (Var "y") (TyVar "b")]
+ res <- runTestClient serverPort ".newenv1" inp
- -- res `shouldBe` expectedOutput
+ res `shouldBe` expectedOutput
it "allows retrieving empty initial env" $ \Server {serverPort} -> do
- let inp = [Com DumpEnv]
- expectedOutput = [Right $ CurrentEnv newEnv newContext]
+ let inp = [Com (Set (SelectLanguage Untyped)), Com DumpEnv]
+ expectedOutput =
+ [ Right (Msg "Language set to Untyped"),
+ Right $ CurrentEnv newEnv newContext Untyped
+ ]
res <- runTestClient serverPort ".newenv2" inp
res `shouldBe` expectedOutput
diff --git a/lambda-calcul/haskell/test/Minilang/REPLSpec.hs b/lambda-calcul/haskell/test/Minilang/REPLSpec.hs
index d23ffbd..5469a59 100644
--- a/lambda-calcul/haskell/test/Minilang/REPLSpec.hs
+++ b/lambda-calcul/haskell/test/Minilang/REPLSpec.hs
@@ -47,7 +47,8 @@ spec = parallel $
out
`shouldBe` [ "Bye!",
- "(lam (z s) (s ((lam (n z s) (s n)) (lam (z s) z)))) : <?>"
+ "(lam (z s) (s ((lam (n z s) (s n)) (lam (z s) z)))) : <?>",
+ "Language set to Untyped"
]
it "shows error when trying to load a non-existent file" $ do