{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE PatternGuards #-}
module Distribution.Backpack.ModSubst (
ModSubst(..),
) where
import Prelude ()
import Distribution.Compat.Prelude hiding (mod)
import Distribution.ModuleName
import Distribution.Backpack
import qualified Data.Map as Map
import Data.Set (Set)
import qualified Data.Set as Set
class ModSubst a where
modSubst :: OpenModuleSubst -> a -> a
instance ModSubst OpenModule where
modSubst subst (OpenModule cid mod_name) = OpenModule (modSubst subst cid) mod_name
modSubst subst mod@(OpenModuleVar mod_name)
| Just mod' <- Map.lookup mod_name subst = mod'
| otherwise = mod
instance ModSubst OpenUnitId where
modSubst subst (IndefFullUnitId cid insts) = IndefFullUnitId cid (modSubst subst insts)
modSubst _subst uid = uid
instance ModSubst (Set ModuleName) where
modSubst subst reqs
= Set.union (Set.difference reqs (Map.keysSet subst))
(openModuleSubstFreeHoles subst)
instance ModSubst a => ModSubst (Map k a) where
modSubst subst = fmap (modSubst subst)
instance ModSubst a => ModSubst [a] where
modSubst subst = fmap (modSubst subst)
instance ModSubst a => ModSubst (k, a) where
modSubst subst (x,y) = (x, modSubst subst y)