Add signature of inferred bind to allow some mutually defined definitions

This commit is contained in:
Martin Fredin 2023-03-30 12:35:47 +02:00
parent a37a52d9f8
commit bbe0d77a19
4 changed files with 111 additions and 28 deletions

View file

@ -31,6 +31,8 @@ testTypeCheckerBidir = describe "Bidirectional type checker test" $ do
tc_tree
tc_mono_case
tc_pol_case
tc_mut_rec
tc_infer_case
tc_id =
specify "Basic identity function polymorphism" $
@ -266,6 +268,52 @@ tc_pol_case = describe "Polymophic and recursive pattern matching" $ do
, "};"
]
tc_mut_rec = specify "Feasible mutuable recursive definitions" $ run
[ "data Bool () where {"
, " True : Bool ()"
, " False : Bool ()"
, "};"
, "even : Int -> Bool ();"
, "even x = not (odd x);"
, "odd x = not (even x);"
, "not x = case x of {"
, " True => False;"
, " False => True;"
, "};"
] `shouldSatisfy` ok
tc_infer_case = describe "Infer case expression" $ do
specify "Wrong case expression rejected" $
run (fs ++ wrong) `shouldNotSatisfy` ok
specify "Correct case expression accepted" $
run (fs ++ correct) `shouldSatisfy` ok
where
fs =
[ "data Bool () where {"
, " True : Bool ()"
, " False : Bool ()"
, "};"
]
correct =
[ "toBool = case 0 of {"
, " 0 => False;"
, " _ => True;"
, "};"
]
wrong =
[ "toBool = case 0 of {"
, " 0 => False;"
, " _ => 1;"
, "};"
]
run :: [String] -> Err T.Program
run = rmTEVar <=< typecheck <=< pProgram . myLexer . unlines