egison-5.0.0: Programming language with non-linear pattern-matching against non-free data
LicenseMIT
Safe HaskellNone
LanguageGHC2021

Language.Egison.Type.Env

Description

This module provides type environment for the Egison type system.

Synopsis

Documentation

newtype TypeEnv Source #

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

Constructors

TypeEnv 

Instances

Instances details
Show TypeEnv Source # 
Instance details

Defined in Language.Egison.Type.Env

Eq TypeEnv Source # 
Instance details

Defined in Language.Egison.Type.Env

Methods

(==) :: TypeEnv -> TypeEnv -> Bool #

(/=) :: TypeEnv -> TypeEnv -> Bool #

emptyEnv :: TypeEnv Source #

Empty type environment

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.

removeFromEnv :: Var -> TypeEnv -> TypeEnv Source #

Remove a variable from the environment

envToList :: TypeEnv -> [(Var, TypeScheme)] Source #

Convert environment to list

freeVarsInEnv :: TypeEnv -> Set TyVar Source #

Get free type variables in the environment

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

data ClassEnv Source #

Class environment: maps class names to class info and instances

Constructors

ClassEnv 

Fields

Instances

Instances details
Show ClassEnv Source # 
Instance details

Defined in Language.Egison.Type.Env

Eq ClassEnv Source # 
Instance details

Defined in Language.Egison.Type.Env

data ClassInfo Source #

Information about a type class

Constructors

ClassInfo 

Fields

Instances

Instances details
Generic ClassInfo Source # 
Instance details

Defined in Language.Egison.Type.Types

Associated Types

type Rep ClassInfo 
Instance details

Defined in Language.Egison.Type.Types

type Rep ClassInfo = D1 ('MetaData "ClassInfo" "Language.Egison.Type.Types" "egison-5.0.0-IKLJXBVxR779jp4wYu1Icq" 'False) (C1 ('MetaCons "ClassInfo" 'PrefixI 'True) (S1 ('MetaSel ('Just "classSupers") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [String]) :*: (S1 ('MetaSel ('Just "classParam") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TyVar) :*: S1 ('MetaSel ('Just "classMethods") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(String, Type)]))))
Show ClassInfo Source # 
Instance details

Defined in Language.Egison.Type.Types

Eq ClassInfo Source # 
Instance details

Defined in Language.Egison.Type.Types

type Rep ClassInfo Source # 
Instance details

Defined in Language.Egison.Type.Types

type Rep ClassInfo = D1 ('MetaData "ClassInfo" "Language.Egison.Type.Types" "egison-5.0.0-IKLJXBVxR779jp4wYu1Icq" 'False) (C1 ('MetaCons "ClassInfo" 'PrefixI 'True) (S1 ('MetaSel ('Just "classSupers") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [String]) :*: (S1 ('MetaSel ('Just "classParam") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TyVar) :*: S1 ('MetaSel ('Just "classMethods") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(String, Type)]))))

data InstanceInfo Source #

Information about a type class instance

Constructors

InstanceInfo 

Fields

Instances

Instances details
Generic InstanceInfo Source # 
Instance details

Defined in Language.Egison.Type.Types

Associated Types

type Rep InstanceInfo 
Instance details

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, ())]))))
Show InstanceInfo Source # 
Instance details

Defined in Language.Egison.Type.Types

Eq InstanceInfo Source # 
Instance details

Defined in Language.Egison.Type.Types

type Rep InstanceInfo Source # 
Instance details

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

addClass :: String -> ClassInfo -> ClassEnv -> ClassEnv Source #

Add a class to the environment

addInstance :: String -> InstanceInfo -> ClassEnv -> ClassEnv Source #

Add an instance to the environment

lookupClass :: String -> ClassEnv -> Maybe ClassInfo Source #

Look up a class definition

lookupInstances :: String -> ClassEnv -> [InstanceInfo] Source #

Look up instances for a class

classEnvToList :: ClassEnv -> [(String, ClassInfo)] Source #

Convert class environment to list

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

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