| License | MIT |
|---|---|
| Safe Haskell | None |
| Language | GHC2021 |
Language.Egison.Type.Env
Description
This module provides type environment for the Egison type system.
Synopsis
- newtype TypeEnv = TypeEnv {
- unTypeEnv :: Map String [VarEntry TypeScheme]
- emptyEnv :: TypeEnv
- extendEnv :: Var -> TypeScheme -> TypeEnv -> TypeEnv
- extendEnvMany :: [(Var, TypeScheme)] -> TypeEnv -> TypeEnv
- lookupEnv :: Var -> TypeEnv -> Maybe TypeScheme
- removeFromEnv :: Var -> TypeEnv -> TypeEnv
- envToList :: TypeEnv -> [(Var, TypeScheme)]
- freeVarsInEnv :: TypeEnv -> Set TyVar
- generalize :: TypeEnv -> Type -> TypeScheme
- instantiate :: TypeScheme -> Int -> ([Constraint], Type, Int)
- data ClassEnv = ClassEnv {}
- data ClassInfo = ClassInfo {
- classSupers :: [String]
- classParam :: TyVar
- classMethods :: [(String, Type)]
- data InstanceInfo = InstanceInfo {
- instContext :: [Constraint]
- instClass :: String
- instType :: Type
- instMethods :: [(String, ())]
- emptyClassEnv :: ClassEnv
- addClass :: String -> ClassInfo -> ClassEnv -> ClassEnv
- addInstance :: String -> InstanceInfo -> ClassEnv -> ClassEnv
- lookupClass :: String -> ClassEnv -> Maybe ClassInfo
- lookupInstances :: String -> ClassEnv -> [InstanceInfo]
- classEnvToList :: ClassEnv -> [(String, ClassInfo)]
- mergeClassEnv :: ClassEnv -> ClassEnv -> ClassEnv
- newtype PatternTypeEnv = PatternTypeEnv {}
- emptyPatternEnv :: PatternTypeEnv
- extendPatternEnv :: String -> TypeScheme -> PatternTypeEnv -> PatternTypeEnv
- lookupPatternEnv :: String -> PatternTypeEnv -> Maybe TypeScheme
- patternEnvToList :: PatternTypeEnv -> [(String, TypeScheme)]
Documentation
Type environment: uses same data structure as evaluation environment Maps base variable names to all bindings with that name VarEntry list is sorted by index length (shortest first) for efficient prefix matching
Instances
extendEnv :: Var -> TypeScheme -> TypeEnv -> TypeEnv Source #
Extend the environment with a new binding
extendEnvMany :: [(Var, TypeScheme)] -> TypeEnv -> TypeEnv Source #
Extend the environment with multiple bindings
lookupEnv :: Var -> TypeEnv -> Maybe TypeScheme Source #
Look up a variable in the environment Search algorithm (same as refVar in Data.hs): 1. Try exact match 2. Try prefix match (find longer indices and auto-complete with #) 3. Try suffix removal (find shorter indices, pick longest match) No recursion is used; all matching is done in a single pass to avoid infinite loops.
generalize :: TypeEnv -> Type -> TypeScheme Source #
Generalize a type to a type scheme (without constraints) Generalize all free type variables that are not in the environment
instantiate :: TypeScheme -> Int -> ([Constraint], Type, Int) Source #
Instantiate a type scheme with fresh type variables Returns a tuple of (constraints, instantiated type, fresh variable counter)
Class environment
Class environment: maps class names to class info and instances
Constructors
| ClassEnv | |
Fields
| |
Information about a type class
Constructors
| ClassInfo | |
Fields
| |
Instances
data InstanceInfo Source #
Information about a type class instance
Constructors
| InstanceInfo | |
Fields
| |
Instances
| Generic InstanceInfo Source # | |||||
Defined in Language.Egison.Type.Types Associated Types
| |||||
| Show InstanceInfo Source # | |||||
Defined in Language.Egison.Type.Types Methods showsPrec :: Int -> InstanceInfo -> ShowS # show :: InstanceInfo -> String # showList :: [InstanceInfo] -> ShowS # | |||||
| Eq InstanceInfo Source # | |||||
Defined in Language.Egison.Type.Types | |||||
| type Rep InstanceInfo Source # | |||||
Defined in Language.Egison.Type.Types type Rep InstanceInfo = D1 ('MetaData "InstanceInfo" "Language.Egison.Type.Types" "egison-5.0.0-IKLJXBVxR779jp4wYu1Icq" 'False) (C1 ('MetaCons "InstanceInfo" 'PrefixI 'True) ((S1 ('MetaSel ('Just "instContext") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Constraint]) :*: S1 ('MetaSel ('Just "instClass") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)) :*: (S1 ('MetaSel ('Just "instType") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Type) :*: S1 ('MetaSel ('Just "instMethods") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(String, ())])))) | |||||
emptyClassEnv :: ClassEnv Source #
Empty class environment
addInstance :: String -> InstanceInfo -> ClassEnv -> ClassEnv Source #
Add an instance to the environment
lookupInstances :: String -> ClassEnv -> [InstanceInfo] Source #
Look up instances for a class
mergeClassEnv :: ClassEnv -> ClassEnv -> ClassEnv Source #
Merge two class environments The second environment's definitions take precedence in case of conflicts
Pattern type environment
newtype PatternTypeEnv Source #
Pattern type environment: maps pattern function names to type schemes This is separate from the value type environment
Constructors
| PatternTypeEnv | |
Fields | |
Instances
| Show PatternTypeEnv Source # | |
Defined in Language.Egison.Type.Env Methods showsPrec :: Int -> PatternTypeEnv -> ShowS # show :: PatternTypeEnv -> String # showList :: [PatternTypeEnv] -> ShowS # | |
| Eq PatternTypeEnv Source # | |
Defined in Language.Egison.Type.Env Methods (==) :: PatternTypeEnv -> PatternTypeEnv -> Bool # (/=) :: PatternTypeEnv -> PatternTypeEnv -> Bool # | |
emptyPatternEnv :: PatternTypeEnv Source #
Empty pattern type environment
extendPatternEnv :: String -> TypeScheme -> PatternTypeEnv -> PatternTypeEnv Source #
Extend the pattern type environment with a new binding
lookupPatternEnv :: String -> PatternTypeEnv -> Maybe TypeScheme Source #
Look up a pattern constructor/function in the environment
patternEnvToList :: PatternTypeEnv -> [(String, TypeScheme)] Source #
Convert pattern type environment to list