sifflet-lib-2.0.0.0: Library of modules shared by sifflet and its tests and its exporters.

Safe HaskellSafe-Infered

Language.Sifflet.TypeCheck

Synopsis

Documentation

valueType :: Value -> SuccFail TypeSource

Determine the type of a value. May result in a type variable.

typeCheckValues :: [String] -> [Type] -> [Value] -> SuccFail [Value]Source

Check whether the values agree with the types (which may be abstract)

This is *probably* too lenient in the case of type variables: it can pass a mixed-type list.

type Subst = TypeVarName -> TypeSource

The type of a substitution function, which maps type variables to types

subst :: Subst -> Type -> TypeSource

Apply a substitution function to a type (possibly a type with variables)

substComp :: Subst -> Subst -> SubstSource

Composing two substitutions

idSubst :: SubstSource

Identity substitution

deltaSubst :: TypeVarName -> Type -> SubstSource

A delta substitution is one that affects just a single variable.

extend :: Subst -> TypeVarName -> Type -> SuccFail SubstSource

Try to extend a substitution by adding a single variable-value pair

data TypeScheme Source

A TypeScheme (TypeScheme schematicVariables typeExpression) is a sort of type template, in which schematic variables (i.e., type parameters or generics) are made explicit; any other type variables in the type expression are unknowns

Constructors

TypeScheme [TypeVarName] Type 

substTS :: Subst -> TypeScheme -> TypeSchemeSource

Apply a substitution to a type scheme, taking care to affect only the unknowns, not the schematic variables

type TypeEnv = Map TypeVarName TypeSchemeSource

A type environment maps type variable names to type schemes. Oh, is it really type variable names, or just names? It seems to me that in envToTypeEnv, it's function names, instead of type variable names.

install :: TypeEnv -> TypeVarName -> TypeScheme -> TypeEnvSource

Insert a new type variable and its type scheme value

unknownsTE :: TypeEnv -> [TypeVarName]Source

The unknowns of a type environment

data NameSupply Source

A source of variable names

Constructors

NameSupply TypeVarName Int 

newNameSupply :: TypeVarName -> NameSupplySource

Creates a name supply

nameSupplyNext :: NameSupply -> (TypeVarName, NameSupply)Source

Produces next variable from a name supply

nameSupplyTake :: NameSupply -> Int -> ([TypeVarName], NameSupply)Source

Produces next several variables from a name supply

tcExpr :: TypeEnv -> NameSupply -> Expr -> SuccFail (Subst, Type, NameSupply)Source

Type check an expression

tcVar :: TypeEnv -> NameSupply -> String -> SuccFail (Subst, Type, NameSupply)Source

Type check a variable (actually the variable name). Find the type scheme associated with the variable in the type environment. Return a new instance of the type scheme, in which its schematic variables are replaced by new variables, and the unknowns are left as they are.

envToTypeEnv :: Env -> TypeEnvSource

Create a TypeEnv from an Env Bindings on the left replace bindings of the same name on the right, if any.

baseTypeEnv :: TypeEnvSource

The base type environment, derived from the base environment of the Sifflet language (built-in functions)

decideTypes :: String -> Expr -> [String] -> Env -> SuccFail ([Type], Type)Source

Decide the type of a function -- called by the function editor when the Apply button is clicked. decideTypes tries to find the argument types and return type of an expression considered as the body of a function, at the same time checking for consistency of inputs and outputs between the parts of the expression. It returns Succ (argtypes, returntype) if successful; Fail errormessage otherwise.