summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/test/Minilang/Lambda
diff options
context:
space:
mode:
authorArnaud Bailly <arnaud@pankzsoft.com>2025-10-28 20:14:16 +0100
committerArnaud Bailly <arnaud@pankzsoft.com>2025-10-28 20:14:16 +0100
commit1d1f0efc7de1eaa0c8a6b503892c2f950008fde6 (patch)
treebd2e2ea5963d8a208d302854502f580d8ffd73cb /lambda-calcul/haskell/test/Minilang/Lambda
parenta210419fd60c00d011f70fb1b968031621e4c01a (diff)
downloadlambda-nantes-1d1f0efc7de1eaa0c8a6b503892c2f950008fde6.tar.gz
wip: port REPL from minilang
Diffstat (limited to 'lambda-calcul/haskell/test/Minilang/Lambda')
-rw-r--r--lambda-calcul/haskell/test/Minilang/Lambda/DeBruijnSpec.hs8
-rw-r--r--lambda-calcul/haskell/test/Minilang/Lambda/EvalSpec.hs87
2 files changed, 49 insertions, 46 deletions
diff --git a/lambda-calcul/haskell/test/Minilang/Lambda/DeBruijnSpec.hs b/lambda-calcul/haskell/test/Minilang/Lambda/DeBruijnSpec.hs
index ef8903c..cff047d 100644
--- a/lambda-calcul/haskell/test/Minilang/Lambda/DeBruijnSpec.hs
+++ b/lambda-calcul/haskell/test/Minilang/Lambda/DeBruijnSpec.hs
@@ -1,8 +1,10 @@
+{-# LANGUAGE TypeApplications #-}
module Minilang.Lambda.DeBruijnSpec where
import Minilang.Lambda.DeBruijn (DeBruijn (..), eval, toDeBruijn)
import qualified Minilang.Lambda.Eval as Eval
import Test.Hspec (Spec, it, shouldBe)
+import Data.Text (Text)
spec :: Spec
spec = do
@@ -10,9 +12,9 @@ spec = do
let term = Eval.Lam "x" (Eval.Lam "y" (Eval.Var "x"))
deBruijn = toDeBruijn term
- deBruijn `shouldBe` Lam (Lam (Var 1))
+ deBruijn `shouldBe` Lam "x" (Lam "y" (Var "x" 1))
it "evaluates deBruijn term" $ do
- let term = App (App (Lam (Lam (Var 1))) (Var 12)) (Var 34)
+ let term = App (App (Lam "x" (Lam "y" (Var "x" 1))) (FV "z")) (FV "t")
- eval term `shouldBe` Var 12
+ eval @Text term `shouldBe` FV "z"
diff --git a/lambda-calcul/haskell/test/Minilang/Lambda/EvalSpec.hs b/lambda-calcul/haskell/test/Minilang/Lambda/EvalSpec.hs
index 718b46d..89e86b9 100644
--- a/lambda-calcul/haskell/test/Minilang/Lambda/EvalSpec.hs
+++ b/lambda-calcul/haskell/test/Minilang/Lambda/EvalSpec.hs
@@ -2,51 +2,52 @@ module Minilang.Lambda.EvalSpec (spec) where
import Control.Concurrent (threadDelay)
import Control.Concurrent.Async (race_)
-import Minilang.Lambda.Eval (Term (..), Value (..), eval, evalNeed)
-import Test.Hspec (Spec, describe, it, shouldBe)
+import Minilang.Lambda.Eval (Term (..), eval, evalNeed)
+import Test.Hspec (Spec, describe, it, pending, shouldBe)
spec :: Spec
-spec = do
- let fix =
- Lam
- "f"
- ( App
- (Lam "x" (App (Var "f") (App (Var "x") (Var "x"))))
- (Lam "x" (App (Var "f") (App (Var "x") (Var "x"))))
- )
- let omega = App fix fix
- let term = App (App (Lam "x" (Lam "y" (Var "y"))) omega) (Var "z")
- let fst' = Lam "x" (Lam "y" (Var "x"))
+spec = it "evaluates Term" pending
- describe "call-by-value eval" $ do
- it "evaluates 'x' as itself" $ do
- let term = Var "x"
- eval term [] `shouldBe` V "x"
- it "evaluates '((λ x. x) y)' as 'y'" $ do
- let term = App (Lam "x" (Var "x")) (Var "y")
- eval term [] `shouldBe` V "y"
- it "evaluates '((λ x y. y) z t y)' as '(t y)'" $ do
- let snd' = Lam "x" (Lam "y" (Var "y"))
- let term = App (App (App snd' (Var "z")) (Var "t")) (Var "y")
- eval term [] `shouldBe` Ap (V "t") (V "y")
- it "evaluates '((λ x y. x) z t)' as 'z'" $ do
- let term = App (App fst' (Var "z")) (Var "t")
- eval term [] `shouldBe` V "z"
- it "diverges on evaluating argument bound to ω" $
- shouldDiverge $
- eval term []
+-- let fix =
+-- Lam
+-- "f"
+-- ( App
+-- (Lam "x" (App (Var "f") (App (Var "x") (Var "x"))))
+-- (Lam "x" (App (Var "f") (App (Var "x") (Var "x"))))
+-- )
+-- let omega = App fix fix
+-- let term = App (App (Lam "x" (Lam "y" (Var "y"))) omega) (Var "z")
+-- let fst' = Lam "x" (Lam "y" (Var "x"))
- describe "call-by-need eval" $ do
- it "evaluates 'x' as itself" $ do
- evalNeed (Var "x") [] `shouldBe` V "x"
- it "evaluates '(λ x y . y) ⊥ z' as 'z'" $ do
- evalNeed term [] `shouldBe` V "z"
- it "diverges on evaluating ω" $
- shouldDiverge $
- evalNeed omega []
+-- describe "call-by-value eval" $ do
+-- it "evaluates 'x' as itself" $ do
+-- let term = Var "x"
+-- eval term [] `shouldBe` V "x"
+-- it "evaluates '((λ x. x) y)' as 'y'" $ do
+-- let term = App (Lam "x" (Var "x")) (Var "y")
+-- eval term [] `shouldBe` V "y"
+-- it "evaluates '((λ x y. y) z t y)' as '(t y)'" $ do
+-- let snd' = Lam "x" (Lam "y" (Var "y"))
+-- let term = App (App (App snd' (Var "z")) (Var "t")) (Var "y")
+-- eval term [] `shouldBe` Ap (V "t") (V "y")
+-- it "evaluates '((λ x y. x) z t)' as 'z'" $ do
+-- let term = App (App fst' (Var "z")) (Var "t")
+-- eval term [] `shouldBe` V "z"
+-- it "diverges on evaluating argument bound to ω" $
+-- shouldDiverge $
+-- eval term []
-shouldDiverge :: Value -> IO ()
-shouldDiverge t =
- race_
- (t `seq` fail "Did not diverge")
- (threadDelay 1000000)
+-- describe "call-by-need eval" $ do
+-- it "evaluates 'x' as itself" $ do
+-- evalNeed (Var "x") [] `shouldBe` V "x"
+-- it "evaluates '(λ x y . y) ⊥ z' as 'z'" $ do
+-- evalNeed term [] `shouldBe` V "z"
+-- it "diverges on evaluating ω" $
+-- shouldDiverge $
+-- evalNeed omega []
+
+-- shouldDiverge :: Value -> IO ()
+-- shouldDiverge t =
+-- race_
+-- (t `seq` fail "Did not diverge")
+-- (threadDelay 1000000)