@@ -3,6 +3,7 @@ module Test.KindCheck (test) where
33import Data.Text (Text )
44import LambdaBuffers.Compiler.KindCheck (
55 check_ ,
6+ foldWithArrowToType ,
67 foldWithProduct ,
78 foldWithSum ,
89 )
@@ -11,6 +12,7 @@ import LambdaBuffers.Compiler.KindCheck.Variable (
1112 Variable (LocalRef ),
1213 )
1314
15+ import LambdaBuffers.Compiler.KindCheck.Inference (Kind (Type , (:->:) ))
1416import Test.KindCheck.Errors (testGKindCheckErrors )
1517import Test.QuickCheck (
1618 Arbitrary (arbitrary ),
@@ -30,13 +32,15 @@ import Test.Utils.Constructors (_CompilerInput)
3032-- Top Level tests
3133
3234test :: TestTree
33- test = testGroup " Compiler tests" [testCheck, testFolds, testGKindCheckErrors]
35+ test =
36+ testGroup " Compiler tests" [testCheck, testFolds, testGKindCheckErrors]
3437
3538--------------------------------------------------------------------------------
3639-- Module tests
3740
3841testCheck :: TestTree
39- testCheck = testGroup " KindChecker Tests" [trivialKCTest, kcTestMaybe, kcTestFailing]
42+ testCheck =
43+ testGroup " KindChecker Tests" [trivialKCTest, kcTestMaybe, kcTestFailing]
4044
4145trivialKCTest :: TestTree
4246trivialKCTest =
@@ -61,8 +65,15 @@ testFolds :: TestTree
6165testFolds =
6266 testGroup
6367 " Test Folds"
64- [ testGroup " Test Product Folds" [testFoldProd0, testFoldProd1, testFoldProd2, testFoldProd3, testPProdFoldTotal]
65- , testGroup " Test Sum Folds" [testSumFold0, testSumFold1, testSumFold2, testSumFold3]
68+ [ testGroup
69+ " Test Product Folds"
70+ [testFoldProd0, testFoldProd1, testFoldProd2, testFoldProd3, testPProdFoldTotal]
71+ , testGroup
72+ " Test Sum Folds"
73+ [testSumFold0, testSumFold1, testSumFold2, testSumFold3]
74+ , testGroup
75+ " Test Arrow Folds"
76+ [testArrowFold0, testArrowFold1, testArrowFold2, testArrowFold3HK, testArrowFold4HK, testArrowFoldHHK]
6677 ]
6778
6879prod :: Type -> Type -> Type
@@ -135,6 +146,48 @@ testSumFold3 =
135146 foldWithSum [lVar " c" , lVar " b" , lVar " a" ]
136147 @?= sum' (sum' (sum' void' (lVar " c" )) (lVar " b" )) (lVar " a" )
137148
149+ ty :: Kind
150+ ty = Type
151+
152+ -- | [ ] -> *
153+ testArrowFold0 :: TestTree
154+ testArrowFold0 =
155+ testCase " Fold 0 kinds" $
156+ foldWithArrowToType [] @?= ty
157+
158+ -- | [*] => * -> *
159+ testArrowFold1 :: TestTree
160+ testArrowFold1 =
161+ testCase " Fold 1 kinds" $
162+ foldWithArrowToType [ty] @?= ty :->: ty
163+
164+ -- | [*,*] => * -> * -> *
165+ testArrowFold2 :: TestTree
166+ testArrowFold2 =
167+ testCase " Fold 2 kinds" $
168+ foldWithArrowToType [ty, ty] @?= ty :->: (ty :->: ty)
169+
170+ -- | [* -> *, * ] => (* -> *) -> * -> *
171+ testArrowFold3HK :: TestTree
172+ testArrowFold3HK =
173+ testCase " Fold 2 HKT" $
174+ foldWithArrowToType [ty :->: ty, ty]
175+ @?= ((ty :->: ty) :->: (ty :->: ty))
176+
177+ -- | [*, * -> *, * ] => * -> (* -> *) -> * -> *
178+ testArrowFold4HK :: TestTree
179+ testArrowFold4HK =
180+ testCase " Fold 2 HKT" $
181+ foldWithArrowToType [ty, ty :->: ty, ty]
182+ @?= (ty :->: ((ty :->: ty) :->: (ty :->: ty)))
183+
184+ -- | [*, * -> *, * ] => * -> ((* -> *) -> *) -> * -> *
185+ testArrowFoldHHK :: TestTree
186+ testArrowFoldHHK =
187+ testCase " Fold 2 HKT" $
188+ foldWithArrowToType [ty, (ty :->: ty) :->: ty, ty]
189+ @?= (ty :->: (((ty :->: ty) :->: ty) :->: (ty :->: ty)))
190+
138191-- | TyDef to Kind Canonical representation - sums not folded - therefore we get constructor granularity. Might use in a different implementation for more granular errors.
139192lVar :: Text -> Type
140193lVar = Var . LocalRef
0 commit comments