purescript-0.15.15: PureScript Programming Language Compiler

Safe Haskell | None
Language | Haskell2010

Language.PureScript.TypeChecker.Unify

Description

Functions and instances relating to unification

Synopsis

- freshType :: MonadState CheckState m => m SourceType
- freshTypeWithKind :: MonadState CheckState m => SourceType -> m SourceType
- solveType :: (MonadError MultipleErrors m, MonadState CheckState m) => Int -> SourceType -> m ()
- substituteType :: Substitution -> SourceType -> SourceType
- unknownsInType :: Type a -> [(a, Int)]
- unifyTypes :: (MonadError MultipleErrors m, MonadState CheckState m) => SourceType -> SourceType -> m ()
- unifyRows :: (MonadError MultipleErrors m, MonadState CheckState m) => SourceType -> SourceType -> m ()
- alignRowsWith :: (Label -> Type a -> Type a -> r) -> Type a -> Type a -> ([r], (([RowListItem a], Type a), ([RowListItem a], Type a)))
- replaceTypeWildcards :: (MonadWriter MultipleErrors m, MonadState CheckState m) => SourceType -> m SourceType
- varIfUnknown :: MonadState CheckState m => [(Unknown, SourceType)] -> SourceType -> m SourceType

# Documentation

freshType :: MonadState CheckState m => m SourceType #

Generate a fresh type variable with an unknown kind. Avoid this if at all possible.

freshTypeWithKind :: MonadState CheckState m => SourceType -> m SourceType #

Generate a fresh type variable with a known kind.

solveType :: (MonadError MultipleErrors m, MonadState CheckState m) => Int -> SourceType -> m () #

Update the substitution to solve a type constraint

substituteType :: Substitution -> SourceType -> SourceType #

Apply a substitution to a type

unknownsInType :: Type a -> [(a, Int)] #

Compute a list of all unknowns appearing in a type

unifyTypes :: (MonadError MultipleErrors m, MonadState CheckState m) => SourceType -> SourceType -> m () #

Unify two types, updating the current substitution

unifyRows :: (MonadError MultipleErrors m, MonadState CheckState m) => SourceType -> SourceType -> m () #

Unify two rows, updating the current substitution

Common labels are identified and unified. Remaining labels and types are unified with a trailing row unification variable, if appropriate.

alignRowsWith :: (Label -> Type a -> Type a -> r) -> Type a -> Type a -> ([r], (([RowListItem a], Type a), ([RowListItem a], Type a))) #

Align two rows of types, splitting them into three parts:

- Those types which appear in both rows
- Those which appear only on the left
- Those which appear only on the right

Note: importantly, we preserve the order of the types with a given label.

replaceTypeWildcards :: (MonadWriter MultipleErrors m, MonadState CheckState m) => SourceType -> m SourceType #

Replace type wildcards with unknowns

varIfUnknown :: MonadState CheckState m => [(Unknown, SourceType)] -> SourceType -> m SourceType #

Replace outermost unsolved unification variables with named type variables