Skip to content
This repository was archived by the owner on Oct 18, 2021. It is now read-only.

Commit 84d9123

Browse files
committed
fix unification
nice commit message
1 parent a533b7c commit 84d9123

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

amuletml.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: amuletml
2-
version: 0.1.0.0
2+
version: 0.2.0.0
33
synopsis: A functional programming language
44
homepage: https://amulet.ml
55
license: BSD3

src/Types/Unify.hs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,15 +655,27 @@ unify scope (TyOperator l v r) (TyOperator l' v' r')
655655

656656
unify scope ta@(TyApps (TyCon v) xs@(_:_)) b = do
657657
x <- view solveInfo
658+
traceM (show (x ^. at v))
658659
case x ^. at v of
659660
Just (Right tf) -> unifyTyFunApp tf scope xs b
660661
_ -> case b of
662+
TyApps (TyCon v) ys | Just (Right tf) <- x ^. at v -> SymCo <$> unify scope b ta
663+
661664
TyApps f ys | length xs == length ys -> rethrow ta b $ do
662665
heads <- unify scope (TyCon v) f
663666
tails <- traverse (uncurry (unify scope)) (zip xs ys)
664667
pure (foldl AppCo heads tails)
668+
665669
TyApps f ys | length ys < length xs -> rethrow ta b $ do
666-
let (xs_a, xs_b) = splitAt (length ys) xs
670+
case f of
671+
TyCon{} -> confesses =<< unequal ta b
672+
_ -> pure ()
673+
674+
let ys_l = length ys
675+
xs_l = length xs
676+
xs_a = take (xs_l - ys_l) xs
677+
xs_b = drop (xs_l - ys_l) xs
678+
667679
heads <- unify scope (TyApps (TyCon v) xs_a) f
668680
tails <- traverse (uncurry (unify scope)) (zip xs_b ys)
669681
pure (foldl AppCo heads tails)
@@ -675,7 +687,6 @@ unify scope a tb@(TyApps (TyCon _) (_:_)) = rethrow a tb $ SymCo <$> unify scope
675687

676688
unify scope (TyApp f x) (TyApp g y) = AppCo <$> unify scope f g <*> unify scope x y
677689

678-
679690
unify _ TyType TyType = pure (ReflCo TyType)
680691
unify _ a b = confesses =<< unequal a b -- }}}
681692

tests/types/unify.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type sum 'f 'g 'a =
2+
| L1 of 'f 'a
3+
4+
type k1 'c 'a = K1 of 'c
5+
type m1 'f 'a = M1 of 'f 'a
6+
7+
let f x = M1 (L1 (M1 (K1 x)))
8+
9+
let _ = f 123

tests/types/unify.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sum : Infer{'a : type}. Infer{'b : type}. ('b -> type) -> 'a -> 'b -> type
2+
L1 : Spec{'f : 'b -> type}. Spec{'g : 'a}. Spec{'a : 'b}. 'f 'a -> sum 'f 'g 'a
3+
k1 : Infer{'a : type}. type -> 'a -> type
4+
K1 : Spec{'c : type}. Spec{'a : 'a}. 'c -> k1 'c 'a
5+
m1 : Infer{'a : type}. ('a -> type) -> 'a -> type
6+
M1 : Spec{'f : 'a -> type}. Spec{'a : 'a}. 'f 'a -> m1 'f 'a
7+
f : Infer{'a : type}. Infer{'b : 'a}. Infer{'g : 'a}. 'a -> m1 (sum (m1 (k1 'a)) 'g) 'b

0 commit comments

Comments
 (0)