unison-parser-typechecker-0.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Unison.Typechecker

Description

This module is the primary interface to the Unison typechecker module Unison.Typechecker (admissibleTypeAt, check, check', checkAdmissible', equals, locals, subtype, isSubtype, synthesize, synthesize', typeAt, wellTyped) where

Synopsis

Documentation

synthesize :: (Monad f, Var v, BuiltinAnnotation loc, Ord loc, Show loc, Semigroup loc) => PrettyPrintEnv -> PatternMatchCoverageCheckAndKindInferenceSwitch -> Env v loc -> Term v loc -> ResultT (Notes v loc) f (Type v loc) Source #

Infer the type of a Term, using a function to resolve the type of Ref constructors contained in that term.

synthesizeAndResolve :: Monad f => Var v => Monoid loc => BuiltinAnnotation loc => Ord loc => Show loc => PrettyPrintEnv -> Env v loc -> TDNR f v loc (Type v loc) Source #

Infer the type of a Term, using type-directed name resolution to attempt to resolve unknown symbols.

check :: (Monad f, Var v, BuiltinAnnotation loc, Ord loc, Show loc, Semigroup loc) => PrettyPrintEnv -> Env v loc -> Term v loc -> Type v loc -> ResultT (Notes v loc) f (Type v loc) Source #

Check whether a term matches a type, using a function to resolve the type of Ref constructors contained in the term. Returns typ if successful, and a note about typechecking failure otherwise.

wellTyped :: Monad f => Var v => BuiltinAnnotation loc => Ord loc => Show loc => Semigroup loc => PrettyPrintEnv -> Env v loc -> Term v loc -> f Bool Source #

checkAdmissible e t` tests that `(f : t -> r) e` is well-typed. If t has quantifiers, these are moved outside, so if `t : forall a . a`, this will check that `(f : forall a . a -> a) e` is well typed. checkAdmissible' :: Var v => Term v -> Type v -> Either Note (Type v) checkAdmissible' term typ = synthesize' (Term.blank() ann_ tweak typ app_ term) where tweak (Type.ForallNamed' v body) = Type.forall() v (tweak body) tweak t = Type.arrow() t t | Returns True if the expression is well-typed, False otherwise

isEqual :: Var v => Type v loc -> Type v loc -> Bool Source #

isSubtype :: Var v => Type v loc -> Type v loc -> Bool Source #

subtype a b is Right b iff f x is well-typed given x : a and f : b -> t. That is, if a value of type a can be passed to a function expecting a b, then `subtype a b` returns `Right b`. This function returns Left note with information about the reason for subtyping failure otherwise.

Example: subtype (forall a. a -> a) (Int -> Int) returns Right (Int -> Int). subtype :: Var v => Type v -> Type v -> Either Note (Type v) subtype t1 t2 = error "todo" let (t1', t2') = (ABT.vmap TypeVar.Universal t1, ABT.vmap TypeVar.Universal t2) in case Context.runM (Context.subtype t1' t2') (Context.MEnv Context.env0 [] Map.empty True) of Left e -> Left e Right _ -> Right t2

Returns true if subtype t1 t2 returns Right, false otherwise isSubtype :: Var v => Type v -> Type v -> Bool isSubtype t1 t2 = case subtype t1 t2 of Left _ -> False Right _ -> True

Returns true if the two type are equal, up to alpha equivalence and order of quantifier introduction. Note that alpha equivalence considers: `forall b a . a -> b -> a` and `forall a b . a -> b -> a` to be different types equals :: Var v => Type v -> Type v -> Bool equals t1 t2 = isSubtype t1 t2 && isSubtype t2 t1

fitsScheme :: Var v => Type v loc -> Type v loc -> Bool Source #

Similar to isSubtype but treats t2 as a scheme where the outermost variables are existential rather than universal.

For example: let lhs = Unison.Type.ref () (Unison.Builtin.Decls.unitRef) rhs = Unison.Type.forall () (Unison.Var.named "x") (Unison.Type.var () (Unison.Var.named "x")) in fitsScheme Symbol lhs rhs is True@ although the lhs is not a subtype of the rhs.

fitsScheme is used to check that runnable types are a subtype of exists x. '{IO, Exception} x

isMismatchMissingDelay :: Var v => Type v loc -> Type v loc -> Maybe (Either (Type v loc) (Type v loc)) Source #

Checks if the mismatch between two types is due to a missing delay, if so returns a tag for which type is missing the delay

data Env v loc Source #

Constructors

Env 

Fields

Instances

Instances details
Generic (Env v loc) Source # 
Instance details

Defined in Unison.Typechecker

Associated Types

type Rep (Env v loc) :: Type -> Type #

Methods

from :: Env v loc -> Rep (Env v loc) x #

to :: Rep (Env v loc) x -> Env v loc #

type Rep (Env v loc) Source # 
Instance details

Defined in Unison.Typechecker

type Rep (Env v loc) = D1 ('MetaData "Env" "Unison.Typechecker" "unison-parser-typechecker-0.0.0-E7FuwoDrRadBVo69eIX64V" 'False) (C1 ('MetaCons "Env" 'PrefixI 'True) ((S1 ('MetaSel ('Just "ambientAbilities") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Type v loc]) :*: (S1 ('MetaSel ('Just "typeLookup") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (TypeLookup v loc)) :*: S1 ('MetaSel ('Just "termsByShortname") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map Name [Either Name (NamedReference v loc)])))) :*: (S1 ('MetaSel ('Just "freeNameToFuzzyTermsByShortName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map Name (Map Name [Either Name (NamedReference v loc)]))) :*: (S1 ('MetaSel ('Just "topLevelComponents") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map Name (NamedReference v loc))) :*: S1 ('MetaSel ('Just "variances") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map Reference [Variance]))))))

data Notes v loc Source #

Constructors

Notes 

Fields

Instances

Instances details
Monoid (Notes v loc) Source # 
Instance details

Defined in Unison.Typechecker

Methods

mempty :: Notes v loc #

mappend :: Notes v loc -> Notes v loc -> Notes v loc #

mconcat :: [Notes v loc] -> Notes v loc #

Semigroup (Notes v loc) Source # 
Instance details

Defined in Unison.Typechecker

Methods

(<>) :: Notes v loc -> Notes v loc -> Notes v loc #

sconcat :: NonEmpty (Notes v loc) -> Notes v loc #

stimes :: Integral b => b -> Notes v loc -> Notes v loc #

(Var v, Show loc, Ord loc) => Show (Notes v loc) Source # 
Instance details

Defined in Unison.Typechecker

Methods

showsPrec :: Int -> Notes v loc -> ShowS #

show :: Notes v loc -> String #

showList :: [Notes v loc] -> ShowS #

data Resolution v loc Source #

Constructors

Resolution 

Fields

type Name = Text Source #

data NamedReference v loc Source #

Constructors

NamedReference 

Fields

Instances

Instances details
Show v => Show (NamedReference v loc) Source # 
Instance details

Defined in Unison.Typechecker

Methods

showsPrec :: Int -> NamedReference v loc -> ShowS #

show :: NamedReference v loc -> String #

showList :: [NamedReference v loc] -> ShowS #