2 % (c) The GRASP/AQUA Project, Glasgow University, 2000
4 \section[FunDeps]{FunDeps - functional dependencies}
6 It's better to read it as: "if we know these, then we're going to know these"
11 instantiateFdClassTys,
16 #include "HsVersions.h"
18 import Class ( classTvsFds )
19 import Type ( tyVarsOfType )
20 import Outputable ( interppSP, ptext, empty, hsep, punctuate, comma )
21 import UniqSet ( elementOfUniqSet, addOneToUniqSet,
22 uniqSetToList, unionManyUniqSets )
23 import List ( elemIndex )
29 case oclose1 fds vs of
31 (vs', True) -> oclose fds vs'
33 oclose1 [] vs = (vs, False)
34 oclose1 (fd@(ls, rs):fds) vs =
40 vs'b1@(vs', b1) = oclose1 fds vs
41 (vs'', b2) = ounion rs vs'
44 osubset (u:us) vs = if u `elementOfUniqSet` vs then osubset us vs else False
46 ounion [] ys = (ys, False)
48 if x `elementOfUniqSet` ys then (ys', b) else (addOneToUniqSet ys' x, True)
50 (ys', b) = ounion xs ys
52 instantiateFdClassTys clas ts =
53 map (lookupInstFundep tyvars ts) fundeps
55 (tyvars, fundeps) = classTvsFds clas
56 lookupInstFundep tyvars ts (us, vs) =
57 (lookupInstTys tyvars ts us, lookupInstTys tyvars ts vs)
58 lookupInstTys tyvars ts = map (lookupInstTy tyvars ts)
59 lookupInstTy tyvars ts u = ts !! i
60 where Just i = elemIndex u tyvars
63 map (\(xs, ys) -> (unionMap getTyVars xs, unionMap getTyVars ys)) fdtys
65 getTyVars ty = tyVarsOfType ty
66 unionMap f xs = uniqSetToList (unionManyUniqSets (map f xs))
69 pprFundeps fds = hsep (ptext SLIT("|") : punctuate comma (map ppr_fd fds))
71 ppr_fd (us, vs) = hsep [interppSP us, ptext SLIT("->"), interppSP vs]