Explicit local bindings for let/where

This commit is contained in:
2026-07-08 10:27:42 -05:00
parent c6c1ef1fe1
commit 34aee3bf93
6 changed files with 60 additions and 6 deletions

View File

@@ -336,7 +336,7 @@ parser = testGroup "Parser Tests"
, testCase "Parse let expression" $ do
let input = "let x = t t in x"
expect = SApp (SLambda ["x"] (SVar "x" Nothing)) (SApp TLeaf TLeaf)
expect = SLet "x" (SApp TLeaf TLeaf) (SVar "x" Nothing)
parseSingle input @?= expect
, testCase "Evaluate let expression" $ do
@@ -344,18 +344,36 @@ parser = testGroup "Parser Tests"
, testCase "Parse let function binding" $ do
let input = "let f x = x in f t"
expect = SApp (SLambda ["f"] (SApp (SVar "f" Nothing) TLeaf))
(SLambda ["x"] (SVar "x" Nothing))
expect = SLet "f" (SLambda ["x"] (SVar "x" Nothing))
(SApp (SVar "f" Nothing) TLeaf)
parseSingle input @?= expect
, testCase "Parse where expression" $ do
let input = "x where x = t t"
expect = SApp (SLambda ["x"] (SVar "x" Nothing)) (SApp TLeaf TLeaf)
expect = SLet "x" (SApp TLeaf TLeaf) (SVar "x" Nothing)
parseSingle input @?= expect
, testCase "Evaluate where expression" $ do
tricuTestString "x where x = 1" @?= "Fork (Stem Leaf) Leaf"
, testCase "Parse where binding with arguments (SLet)" $ do
let input = "f 3 where f x = x"
expect = SLet "f" (SLambda ["x"] (SVar "x" Nothing))
(SApp (SVar "f" Nothing) (SInt 3))
parseSingle input @?= expect
, testCase "Evaluate where binding with arguments matches applied lambda" $ do
tricuTestString "f (t t) where f x = t x x"
@?= tricuTestString "(f : f (t t)) (x : t x x)"
, testCase "Evaluate nested let bindings" $ do
tricuTestString "let a = t t in let b = t in t a b"
@?= tricuTestString "t (t t) t"
, testCase "Inner let binding shadows outer binding" $ do
tricuTestString "let x = t in let x = t t in x"
@?= tricuTestString "t t"
, testCase "Parse indented multiline definition body" $ do
let input = "x =\n t\n t"
expect = SDef "x" [] (SApp TLeaf TLeaf)