- Nothing -> bale_out item
- Just avail -> succeed_with True avail
-
- check_item item
- | isNothing maybe_in_import_avails ||
- isNothing maybe_filtered_avail
- = Nothing
-
- | otherwise
- = Just filtered_avail
-
- where
- wanted_occ = rdrNameOcc (ieName item)
- maybe_in_import_avails = lookupOccEnv import_fm wanted_occ
-
- Just avail = maybe_in_import_avails
- maybe_filtered_avail = filterAvail item avail
- Just filtered_avail = maybe_filtered_avail
-\end{code}
-
-\begin{code}
-filterAvail :: IE RdrName -- Wanted
- -> AvailInfo -- Available
- -> Maybe AvailInfo -- Resulting available;
- -- Nothing if (any of the) wanted stuff isn't there
-
-filterAvail ie@(IEThingWith want wants) avail@(AvailTC n ns)
- | sub_names_ok = Just (AvailTC n (filter is_wanted ns))
- | otherwise = Nothing
- where
- is_wanted name = nameOccName name `elem` wanted_occs
- sub_names_ok = all (`elem` avail_occs) wanted_occs
- avail_occs = map nameOccName ns
- wanted_occs = map rdrNameOcc (want:wants)
-
-filterAvail (IEThingAbs _) (AvailTC n ns) = ASSERT( n `elem` ns )
- Just (AvailTC n [n])
-
-filterAvail (IEThingAbs _) avail@(Avail n) = Just avail -- Type synonyms
-
-filterAvail (IEVar _) avail@(Avail n) = Just avail
-filterAvail (IEVar v) avail@(AvailTC n ns) = Just (AvailTC n (filter wanted ns))
- where
- wanted n = nameOccName n == occ
- occ = rdrNameOcc v
- -- The second equation happens if we import a class op, thus
- -- import A( op )
- -- where op is a class operation
-
-filterAvail (IEThingAll _) avail@(AvailTC _ _) = Just avail
- -- We don't complain even if the IE says T(..), but
- -- no constrs/class ops of T are available
- -- Instead that's caught with a warning by the caller
-
-filterAvail ie avail = Nothing