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

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

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

Instances details
Show InferState Source # 
Instance details

Defined in Language.Egison.Type.Infer

data InferConfig Source #

Inference configuration

Constructors

InferConfig 

Fields

Instances

Instances details
Show InferConfig Source # 
Instance details

Defined in Language.Egison.Type.Infer

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)

runInfer :: Infer a -> InferState -> IO (Either TypeError a) Source #

Run type inference

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

freshVar :: String -> Infer Type Source #

Generate a fresh type variable

getEnv :: Infer TypeEnv Source #

Get the current type environment

setEnv :: TypeEnv -> Infer () Source #

Set the type environment

withEnv :: [(String, TypeScheme)] -> Infer a -> Infer a Source #

Extend the environment temporarily

lookupVar :: String -> Infer Type Source #

Look up a variable's type

unifyTypes :: Type -> Type -> Infer Subst Source #

Unify two types

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