Unify.hs revision 81d182b21020b815887e9057959228546cf61b6b
453c9b0df0380abe5abb38db3b15530bd3b3dcf5Christian MaederModule : $Header$
453c9b0df0380abe5abb38db3b15530bd3b3dcf5Christian MaederDescription : generalized unification of types
453c9b0df0380abe5abb38db3b15530bd3b3dcf5Christian MaederCopyright : (c) Christian Maeder and Uni Bremen 2003-2005
304c84f22dd78f7979efd81b8fc38c8d2197ed39Christian MaederLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
304c84f22dd78f7979efd81b8fc38c8d2197ed39Christian MaederMaintainer : Christian.Maeder@dfki.de
453c9b0df0380abe5abb38db3b15530bd3b3dcf5Christian MaederStability : experimental
453c9b0df0380abe5abb38db3b15530bd3b3dcf5Christian MaederPortability : portable
453c9b0df0380abe5abb38db3b15530bd3b3dcf5Christian Maedersubstitution and unification of types
453c9b0df0380abe5abb38db3b15530bd3b3dcf5Christian Maederimport qualified Data.Map as Map
4dd227b3f9c659b37083476347d01e2fdd0c71dbChristian Maederimport qualified Data.Set as Set
1256a6994be0c94373a47f8b30747727b24c27faChristian Maeder-- | bound vars
1256a6994be0c94373a47f8b30747727b24c27faChristian MaedergenVarsOf :: Type -> [(Id, RawKind)]
1256a6994be0c94373a47f8b30747727b24c27faChristian MaedergenVarsOf = map snd . leaves (<0)
1256a6994be0c94373a47f8b30747727b24c27faChristian Maeder-- | composition (reversed: first substitution first!)
1256a6994be0c94373a47f8b30747727b24c27faChristian MaedercompSubst :: Subst -> Subst -> Subst
1256a6994be0c94373a47f8b30747727b24c27faChristian MaedercompSubst s1 s2 = Map.union (Map.map (subst s2) s1) s2
1256a6994be0c94373a47f8b30747727b24c27faChristian Maeder-- | unifiability of type schemes including instantiation with fresh variables
1256a6994be0c94373a47f8b30747727b24c27faChristian Maeder-- (and looking up type aliases)
return $ subst (Map.fromList $ zip (map fst ls) ts) t
type Subst = Map.Map Int Type
eps = Map.empty
else if v1 > 0 && b1 then return $ Map.singleton v1 ty2
else if v2 > 0 && b2 then return $ Map.singleton v2 ty1
else if not b1 && b2 && v1 == 0 && v2 == 0 && Set.member i1
else if b1 && not b2 && v1 == 0 && v2 == 0 && Set.member i2
return $ Map.singleton v1 ty2
case Map.lookup n m of
subst $ Map.fromList $ zipWith