on master help sign in
Simplify code for occurs check.
commit9ecb6a705295ce8f29826616a31c71566f353433 authorevancz <info@elm-lang.org> dateThu 3 Jan 2013, 00:28 (14 years ago) parent6af3eb3
1 file changed+1−22
elm/src/Types/Substitutions.hs+1−22
elm/src/Types/Substitutions.hs+1−22
@@ -69,28 +69,7 @@ instance FreeVars a => FreeVars (Context a) where
6969instance FreeVars a => FreeVars [a] where
7070 freeVars = concatMap freeVars
7171
72−class Occurs a where
73− occurs :: X -> a -> Bool
74−
75−instance Occurs Type where
76− occurs v (VarT x) = v == x
77− occurs v (LambdaT t1 t2) = occurs v t1 || occurs v t2
78− occurs v (ADT _ ts) = any (occurs v) ts
79− occurs v (RecordT fs t) = occurs v (concat $ Map.elems fs) || occurs v t
80− occurs v EmptyRecord = False
81− occurs v (Super _ ) = False
82−
83−instance Occurs Constraint where
84− occurs x (t1 :=: t2) = occurs x t1 || occurs x t2
85− occurs x (t1 :<: t2) = occurs x t1 || occurs x t2
86− occurs x (y :<<: Forall xs cs t) = x == y || occurs x t || inCs
87− where inCs = x `notElem` xs && any (occurs x) cs
88−
89−instance Occurs a => Occurs (Context a) where
90− occurs x (C _ _ c) = occurs x c
91−
92−instance Occurs a => Occurs [a] where
93− occurs v = any (occurs v)
72+occurs x t = x `elem` freeVars t
9473
9574concretize :: Scheme -> GuidCounter (Type, [Context Constraint])
9675concretize (Forall xs cs t) = do