1 It's better to read it as: "if we know these, then we're going to know these"
4 module FunDeps(oclose, instantiateFdClassTys, tyVarFunDep, pprFundeps) where
6 #include "HsVersions.h"
8 import Class (classTvsFds)
9 import Type (tyVarsOfType)
10 import Outputable (interppSP, ptext, empty, hsep, punctuate, comma)
11 import UniqSet (elementOfUniqSet, addOneToUniqSet,
12 uniqSetToList, unionManyUniqSets)
13 import List (elemIndex)
16 case oclose1 fds vs of
18 (vs', True) -> oclose fds vs'
20 oclose1 [] vs = (vs, False)
21 oclose1 (fd@(ls, rs):fds) vs =
27 vs'b1@(vs', b1) = oclose1 fds vs
28 (vs'', b2) = ounion rs vs'
31 osubset (u:us) vs = if u `elementOfUniqSet` vs then osubset us vs else False
33 ounion [] ys = (ys, False)
35 if x `elementOfUniqSet` ys then (ys', b) else (addOneToUniqSet ys' x, True)
37 (ys', b) = ounion xs ys
39 instantiateFdClassTys clas ts =
40 map (lookupInstFundep tyvars ts) fundeps
42 (tyvars, fundeps) = classTvsFds clas
43 lookupInstFundep tyvars ts (us, vs) =
44 (lookupInstTys tyvars ts us, lookupInstTys tyvars ts vs)
45 lookupInstTys tyvars ts = map (lookupInstTy tyvars ts)
46 lookupInstTy tyvars ts u = ts !! i
47 where Just i = elemIndex u tyvars
50 map (\(xs, ys) -> (unionMap getTyVars xs, unionMap getTyVars ys)) fdtys
52 getTyVars ty = tyVarsOfType ty
53 unionMap f xs = uniqSetToList (unionManyUniqSets (map f xs))
56 pprFundeps fds = hsep (ptext SLIT("|") : punctuate comma (map ppr_fd fds))
58 ppr_fd (us, vs) = hsep [interppSP us, ptext SLIT("->"), interppSP vs]