@@ -76,11 +76,11 @@ entails env moduleName context = solve
7676 (subst, tcd) <- unique instances
7777 -- Solve any necessary subgoals
7878 args <- solveSubgoals subst (tcdDependencies tcd)
79− return $ foldr (\(superclassName, index) dict -> SubclassDictionaryValue dict superclassName index)
80− (mkDictionary (canonicalizeDictionary tcd) args)
79+ return $ foldr (\(superclassName, index) dict -> SubclassDictionaryValue dict superclassName index)
80+ (mkDictionary (canonicalizeDictionary tcd) args)
8181 (tcdPath tcd)
8282 where
83−
83+
8484 unique :: [(a, TypeClassDictionaryInScope)] -> Check (a, TypeClassDictionaryInScope)
8585 unique [] = throwError . errorMessage $ NoInstanceFound className' tys'
8686 unique [a] = return a
@@ -109,13 +109,13 @@ entails env moduleName context = solve
109109 solveSubgoals subst (Just subgoals) = do
110110 dict <- mapM (uncurry (go (work + 1)) . second (map (replaceAllTypeVars subst))) subgoals
111111 return $ Just dict
112−
112+
113113 -- Make a dictionary from subgoal dictionaries by applying the correct function
114114 mkDictionary :: Qualified Ident -> Maybe [DictionaryValue] -> DictionaryValue
115115 mkDictionary fnName Nothing = LocalDictionaryValue fnName
116116 mkDictionary fnName (Just []) = GlobalDictionaryValue fnName
117117 mkDictionary fnName (Just dicts) = DependentDictionaryValue fnName dicts
118−
118+
119119 -- Turn a DictionaryValue into a Expr
120120 dictionaryValueToValue :: DictionaryValue -> Expr
121121 dictionaryValueToValue (LocalDictionaryValue fnName) = Var fnName
@@ -128,10 +128,10 @@ entails env moduleName context = solve
128128 -- Ensure that a substitution is valid
129129 verifySubstitution :: [(String, Type)] -> Maybe [(String, Type)]
130130 verifySubstitution subst = do
131− let grps = groupBy ((==) `on` fst) subst
131+ let grps = groupBy ((==) `on` fst) . sortBy (compare `on` fst) $ subst
132132 guard (all (pairwise (unifiesWith env) . map snd) grps)
133133 return $ map head grps
134−
134+
135135 valUndefined :: Expr
136136 valUndefined = Var (Qualified (Just (ModuleName [ProperName C.prim])) (Ident C.undefined))
137137
@@ -143,7 +143,7 @@ typeHeadsAreEqual :: ModuleName -> Environment -> Type -> Type -> Maybe [(String
143143typeHeadsAreEqual _ _ (Skolem _ s1 _) (Skolem _ s2 _) | s1 == s2 = Just []
144144typeHeadsAreEqual _ _ t (TypeVar v) = Just [(v, t)]
145145typeHeadsAreEqual _ _ (TypeConstructor c1) (TypeConstructor c2) | c1 == c2 = Just []
146−typeHeadsAreEqual m e (TypeApp h1 t1) (TypeApp h2 t2) = (++) <$> typeHeadsAreEqual m e h1 h2
146+typeHeadsAreEqual m e (TypeApp h1 t1) (TypeApp h2 t2) = (++) <$> typeHeadsAreEqual m e h1 h2
147147 <*> typeHeadsAreEqual m e t1 t2
148148typeHeadsAreEqual m e (SaturatedTypeSynonym name args) t2 = case expandTypeSynonym' e name args of
149149 Left _ -> Nothing
@@ -152,16 +152,16 @@ typeHeadsAreEqual _ _ REmpty REmpty = Just []
152152typeHeadsAreEqual m e r1@(RCons _ _ _) r2@(RCons _ _ _) =
153153 let (s1, r1') = rowToList r1
154154 (s2, r2') = rowToList r2
155−
155+
156156 int = [ (t1, t2) | (name, t1) <- s1, (name', t2) <- s2, name == name' ]
157157 sd1 = [ (name, t1) | (name, t1) <- s1, name `notElem` map fst s2 ]
158158 sd2 = [ (name, t2) | (name, t2) <- s2, name `notElem` map fst s1 ]
159− in (++) <$> foldMap (\(t1, t2) -> typeHeadsAreEqual m e t1 t2) int
159+ in (++) <$> foldMap (\(t1, t2) -> typeHeadsAreEqual m e t1 t2) int
160160 <*> go sd1 r1' sd2 r2'
161161 where
162162 go :: [(String, Type)] -> Type -> [(String, Type)] -> Type -> Maybe [(String, Type)]
163− go [] REmpty [] REmpty = Just []
164− go [] (TUnknown _) _ _ = Just []
163+ go [] REmpty [] REmpty = Just []
164+ go [] (TUnknown _) _ _ = Just []
165165 go [] (TypeVar v1) [] (TypeVar v2) | v1 == v2 = Just []
166166 go [] (Skolem _ s1 _) [] (Skolem _ s2 _) | s1 == s2 = Just []
167167 go sd r [] (TypeVar v) = Just [(v, rowFromList (sd, r))]