| License | MIT |
|---|---|
| Safe Haskell | None |
| Language | GHC2021 |
Language.Egison.Type.Infer
Description
This module provides type inference for IExpr (Internal Expression). This is the unified type inference module for Phase 5-6 of the Egison compiler: IExpr (Desugared, no types) → (Type, Subst)
This module consolidates all type inference functionality, including: - Hindley-Milner type inference - Type class constraint collection - Infer monad and state management - All helper functions
Note: This module only performs type inference and returns Type information. The typed AST (TIExpr) is created in a separate phase by combining IExpr with Type.
Previous modules (Infer.hs for Expr, TypeInfer.hs for Expr→TypedExpr) are deprecated.
Synopsis
- inferIExpr :: IExpr -> Infer (TIExpr, Subst)
- inferITopExpr :: ITopExpr -> Infer (Maybe TITopExpr, Subst)
- inferITopExprs :: [ITopExpr] -> Infer ([Maybe TITopExpr], Subst)
- type Infer a = ExceptT TypeError (StateT InferState IO) a
- data InferState = InferState {}
- data InferConfig = InferConfig {}
- initialInferState :: InferState
- initialInferStateWithConfig :: InferConfig -> InferState
- defaultInferConfig :: InferConfig
- permissiveInferConfig :: InferConfig
- runInfer :: Infer a -> InferState -> IO (Either TypeError a)
- runInferWithWarnings :: Infer a -> InferState -> IO (Either TypeError a, [TypeWarning])
- runInferWithWarningsAndState :: Infer a -> InferState -> IO (Either TypeError a, [TypeWarning], InferState)
- runInferI :: InferConfig -> TypeEnv -> IExpr -> IO (Either TypeError (Type, Subst, [TypeWarning]))
- runInferIWithEnv :: InferConfig -> TypeEnv -> IExpr -> IO (Either TypeError (Type, Subst, TypeEnv, [TypeWarning]))
- freshVar :: String -> Infer Type
- getEnv :: Infer TypeEnv
- setEnv :: TypeEnv -> Infer ()
- withEnv :: [(String, TypeScheme)] -> Infer a -> Infer a
- lookupVar :: String -> Infer Type
- unifyTypes :: Type -> Type -> Infer Subst
- generalize :: TypeEnv -> Type -> TypeScheme
- inferConstant :: ConstantExpr -> Infer Type
- addWarning :: TypeWarning -> Infer ()
- clearWarnings :: Infer ()
Type inference
inferIExpr :: IExpr -> Infer (TIExpr, Subst) Source #
Infer type for IExpr NEW: Returns TIExpr (typed expression) instead of (IExpr, Type, Subst) This builds the recursive TIExpr structure directly during type inference
inferITopExpr :: ITopExpr -> Infer (Maybe TITopExpr, Subst) Source #
Infer top-level IExpr and return TITopExpr directly
inferITopExprs :: [ITopExpr] -> Infer ([Maybe TITopExpr], Subst) Source #
Infer multiple top-level IExprs
Infer monad
type Infer a = ExceptT TypeError (StateT InferState IO) a Source #
Inference monad (with IO for potential future extensions)
data InferState Source #
Inference state
Constructors
| InferState | |
Fields
| |
Instances
| Show InferState Source # | |
Defined in Language.Egison.Type.Infer Methods showsPrec :: Int -> InferState -> ShowS # show :: InferState -> String # showList :: [InferState] -> ShowS # | |
data InferConfig Source #
Inference configuration
Constructors
| InferConfig | |
Fields
| |
Instances
| Show InferConfig Source # | |
Defined in Language.Egison.Type.Infer Methods showsPrec :: Int -> InferConfig -> ShowS # show :: InferConfig -> String # showList :: [InferConfig] -> ShowS # | |
initialInferState :: InferState Source #
Initial inference state
initialInferStateWithConfig :: InferConfig -> InferState Source #
Create initial state with config
defaultInferConfig :: InferConfig Source #
Default configuration (strict mode)
permissiveInferConfig :: InferConfig Source #
Permissive configuration (for gradual adoption)
runInferWithWarnings :: Infer a -> InferState -> IO (Either TypeError a, [TypeWarning]) Source #
Run type inference and also return warnings
runInferWithWarningsAndState :: Infer a -> InferState -> IO (Either TypeError a, [TypeWarning], InferState) Source #
Run inference and return result, warnings, and final state
Running inference
runInferI :: InferConfig -> TypeEnv -> IExpr -> IO (Either TypeError (Type, Subst, [TypeWarning])) Source #
Run type inference on IExpr
runInferIWithEnv :: InferConfig -> TypeEnv -> IExpr -> IO (Either TypeError (Type, Subst, TypeEnv, [TypeWarning])) Source #
Run type inference on IExpr with initial environment
Helper functions
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
inferConstant :: ConstantExpr -> Infer Type Source #
Infer type for constants
addWarning :: TypeWarning -> Infer () Source #
Add a warning
clearWarnings :: Infer () Source #
Clear all accumulated warnings