idris

Safe HaskellNone

Core.TT

Contents

Description

TT is the core language of Idris. The language has:

  • Full dependent types
  • A hierarchy of universes, with cumulativity: Type : Type1, Type1 : Type2, ...
  • Pattern matching letrec binding
  • (primitive types defined externally)

Some technical stuff:

  • Typechecker is kept as simple as possible - no unification, just a checker for incomplete terms.
  • We have a simple collection of tactics which we use to elaborate source programs with implicit syntax into fully explicit terms.

Synopsis

Documentation

data Option Source

Constructors

TTypeInTType 
CheckConv 

Instances

data FC Source

Source location. These are typically produced by the parser getFC

Constructors

FC 

Fields

fc_fname :: String

Filename

fc_line :: Int

Line number

fc_column :: Int

Column number

Instances

Eq FC

Ignore source location equality (so deriving classes do not compare FCs)

Show FC 
Binary FC 
NFData FC 
Sized FC 

newtype FC' Source

FC with equality

Constructors

FC' 

Fields

unwrapFC :: FC
 

Instances

emptyFC :: FCSource

Empty source location

fileFC :: String -> FCSource

 Source location with file only

data TC a Source

Constructors

OK a 
Error Err 

Instances

Monad TC 
Functor TC 
MonadPlus TC 
Eq a => Eq (TC a) 
Show a => Show (TC a) 
Pretty a => Pretty (TC a) 

trun :: FC -> TC a -> TC aSource

discard :: Monad m => m a -> m ()Source

pmap :: (t -> t1) -> (t, t) -> (t1, t1)Source

traceWhen :: Bool -> String -> a -> aSource

data Name Source

Names are hierarchies of strings, describing scope (so no danger of duplicate names, but need to be careful on lookup).

Constructors

UN String

User-provided name

NS Name [String]

Root, namespaces

MN Int String

Machine chosen names

NErased

Name of somethng which is never used in scope

SN SpecialName

Decorated function names

type Ctxt a = Map Name (Map Name a)Source

Contexts allow us to map names to things. A root name maps to a collection of things in different namespaces with that name.

addDef :: Name -> a -> Ctxt a -> Ctxt aSource

lookupCtxtName :: Name -> Ctxt a -> [(Name, a)]Source

Look up a name in the context, given an optional namespace. The name (n) may itself have a (partial) namespace given.

Rules for resolution:

  • if an explicit namespace is given, return the names which match it. If none match, return all names.
  • if the name has has explicit namespace given, return the names which match it and ignore the given namespace.
  • otherwise, return all names.

lookupCtxt :: Name -> Ctxt a -> [a]Source

updateDef :: Name -> (a -> a) -> Ctxt a -> Ctxt aSource

toAlist :: Ctxt a -> [(Name, a)]Source

addAlist :: Show a => [(Name, a)] -> Ctxt a -> Ctxt aSource

intTyWidth :: IntTy -> IntSource

Deprecated: Non-total function, use nativeTyWidth and appropriate casing

data Binder b Source

All binding forms are represented in a unform fashion.

Constructors

Lam 

Fields

binderTy :: b

type annotation for bound variable

Pi 

Fields

binderTy :: b

type annotation for bound variable

Let 

Fields

binderTy :: b

type annotation for bound variable

binderVal :: b

value for bound variable

NLet 

Fields

binderTy :: b

type annotation for bound variable

binderVal :: b

value for bound variable

Hole 

Fields

binderTy :: b

type annotation for bound variable

GHole 

Fields

envlen :: Int
 
binderTy :: b

type annotation for bound variable

Guess 

Fields

binderTy :: b

type annotation for bound variable

binderVal :: b

value for bound variable

PVar 

Fields

binderTy :: b

type annotation for bound variable

PVTy 

Fields

binderTy :: b

type annotation for bound variable

Instances

Functor Binder 
Eq b => Eq (Binder b) 
Ord b => Ord (Binder b) 
Show b => Show (Binder b) 
Binary b => Binary (Binder b) 
NFData b => NFData (Binder b) 
Sized a => Sized (Binder a) 
Optimisable t => Optimisable (Binder t) 
Transform a => Transform (Binder a) 

fmapMB :: Monad m => (a -> m b) -> Binder a -> m (Binder b)Source

data RawFun Source

Constructors

RawFun 

Fields

rtype :: Raw
 
rval :: Raw
 

Instances

data RawDatatype Source

Constructors

RDatatype Name Raw [(Name, Raw)] 

Instances

data RDef Source

Instances

data UExp Source

Universe expressions for universe checking

Constructors

UVar Int

universe variable

UVal Int

explicit universe level

data UConstraint Source

Universe constraints

Constructors

ULT UExp UExp

Strictly less than

ULE UExp UExp

Less than or equal to

data NameType Source

Constructors

Bound 
Ref 
DCon Int Int

Data constructor; Ints are tag and arity

TCon Int Int

Type constructor; Ints are tag and arity

data TT n Source

Terms in the core language

Constructors

P NameType n (TT n)

named references

V Int

a resolved de Bruijn-indexed variable

Bind n (Binder (TT n)) (TT n)

a binding

App (TT n) (TT n)

function, function type, arg

Constant Const

constant

Proj (TT n) Int

argument projection; runtime only (-1) is a special case for 'subtract one from BI'

Erased

an erased term

Impossible

special case for totality checking

TType UExp

the type of types at some level

Instances

class TermSize a whereSource

Methods

termsize :: Name -> a -> IntSource

type EnvTT n = [(n, Binder (TT n))]Source

data Datatype n Source

Constructors

Data 

Fields

d_typename :: n
 
d_typetag :: Int
 
d_type :: TT n
 
d_cons :: [(n, TT n)]
 

Instances

Functor Datatype 
Eq n => Eq (Datatype n) 
(Eq n, Show n) => Show (Datatype n) 

A few handy operations on well typed terms:

isInjective :: TT n -> BoolSource

A term is injective iff it is a data constructor, type constructor, constant, the type Type, pi-binding, or an application of an injective term.

vinstances :: Int -> TT n -> IntSource

Count the number of instances of a de Bruijn index in a term

instantiate :: TT n -> TT n -> TT nSource

substV :: TT n -> TT n -> TT nSource

pToV :: Eq n => n -> TT n -> TT nSource

pToV' :: Eq n => n -> Int -> TT n -> TT nSource

pToVs :: Eq n => [n] -> TT n -> TT nSource

Convert several names. First in the list comes out as V 0

vToP :: TT n -> TT nSource

finalise :: Eq n => TT n -> TT nSource

subst :: Eq n => n -> TT n -> TT n -> TT nSource

substNames :: Eq n => [(n, TT n)] -> TT n -> TT nSource

substTerm :: Eq n => TT n -> TT n -> TT n -> TT nSource

noOccurrence :: Eq n => n -> TT n -> BoolSource

freeNames :: Eq n => TT n -> [n]Source

Returns all names used free in the term

arity :: TT n -> IntSource

Return the arity of a (normalised) type

unApply :: TT n -> (TT n, [TT n])Source

Deconstruct an application; returns the function and a list of arguments

mkApp :: TT n -> [TT n] -> TT nSource

bindAll :: [(n, Binder (TT n))] -> TT n -> TT nSource

bindTyArgs :: (TT n -> Binder (TT n)) -> [(n, TT n)] -> TT n -> TT nSource

getArgTys :: TT n -> [(n, TT n)]Source

getRetTy :: TT n -> TT nSource

newtype WkEnvTT n Source

Constructors

Wk (EnvTT n) 

showEnv :: (Eq a, Show a) => [(a, Binder (TT a))] -> TT a -> [Char]Source

showEnvDbg :: (Eq a, Show a) => [(a, Binder (TT a))] -> TT a -> [Char]Source

prettyEnv :: (Eq a, Show a, Pretty a) => [(a, Binder (TT a))] -> TT a -> DocSource

showEnv' :: (Eq a, Show a) => [(a, Binder (TT a))] -> TT a -> Bool -> [Char]Source

pureTerm :: TT Name -> BoolSource

Check whether a term has any holes in it - impure if so

weakenTm :: Int -> TT n -> TT nSource

Weaken a term by adding i to each de Bruijn index (i.e. lift it over i bindings)

weakenEnv :: EnvTT n -> EnvTT nSource

Weaken an environment so that all the de Bruijn indices are correct according to the latest bound variable