module Retrie.Substitution
( Substitution
, HoleVal(..)
, emptySubst
, extendSubst
, lookupSubst
, deleteSubst
, foldSubst
) where
import Retrie.ExactPrint
import Retrie.GHC
newtype Substitution = Substitution (UniqFM (FastString, HoleVal))
instance Show Substitution where
show (Substitution m) = show (eltsUFM m)
data HoleVal
= HoleExpr AnnotatedHsExpr
| HolePat AnnotatedPat
| HoleType AnnotatedHsType
| HoleRdr RdrName
instance Show HoleVal where
show (HoleExpr e) = "HoleExpr " ++ printA e
show (HolePat p) = "HolePat " ++ printA p
show (HoleType t) = "HoleType " ++ printA t
show (HoleRdr r) = "HoleRdr " ++ unpackFS (rdrFS r)
emptySubst :: Substitution
emptySubst = Substitution emptyUFM
lookupSubst :: FastString -> Substitution -> Maybe HoleVal
lookupSubst k (Substitution m) = snd <$> lookupUFM m k
extendSubst :: Substitution -> FastString -> HoleVal -> Substitution
extendSubst (Substitution m) k v = Substitution (addToUFM m k (k,v))
deleteSubst :: Substitution -> [FastString] -> Substitution
deleteSubst (Substitution m) ks = Substitution (delListFromUFM m ks)
foldSubst :: ((FastString, HoleVal) -> a -> a) -> a -> Substitution -> a
foldSubst f x (Substitution m) = foldUFM f x m