module CSPM.TypeChecker.Environment (
Environment,
new, bind, maybeLookup, update, delete, toList,
mkSymbolInformation, SymbolInformation(..)
)
where
import qualified Data.Map as M
import CSPM.DataStructures.Names
import CSPM.DataStructures.Types
mkSymbolInformation :: TypeScheme -> SymbolInformation
mkSymbolInformation t = SymbolInformation {
typeScheme = t,
isDeprecated = False,
deprecationReplacement = Nothing,
isTypeUnsafe = False
}
data SymbolInformation = SymbolInformation {
typeScheme :: TypeScheme,
isDeprecated :: Bool,
deprecationReplacement :: Maybe Name,
isTypeUnsafe :: Bool
}
deriving (Eq, Show)
type Environment = M.Map Name SymbolInformation
new :: Environment
new = M.empty
bind :: Environment -> [(Name, SymbolInformation)] -> Environment
bind env bs = foldr (\ (n,t) env -> M.insert n t env) env bs
maybeLookup :: Environment -> Name -> Maybe SymbolInformation
maybeLookup env n = M.lookup n env
update :: Environment -> Name -> SymbolInformation -> Environment
update env n s = M.insert n s env
delete :: Environment -> Name -> Environment
delete env n = M.delete n env
toList :: Environment -> [(Name, SymbolInformation)]
toList = M.toList