@@ -1,5 +1,23 @@
11{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, DeriveFunctor #-}
22
3+{-| TT is the core language of Idris. The language has:
4+
5+ * Full dependent types
6+
7+ * A hierarchy of universes, with cumulativity: Type : Type1, Type1 : Type2, ...
8+
9+ * Pattern matching letrec binding
10+
11+ * (primitive types defined externally)
12+
13+ Some technical stuff:
14+
15+ * Typechecker is kept as simple as possible - no unification, just a checker for incomplete terms.
16+
17+ * We have a simple collection of tactics which we use to elaborate source
18+ programs with implicit syntax into fully explicit terms.
19+-}
20+
321module Core.TT where
422
523import Control.Monad.State
@@ -12,19 +30,6 @@ import Data.Binary hiding (get, put)
1230
1331import Util.Pretty hiding (Str)
1432
15−{- The language has:
16− * Full dependent types
17− * A hierarchy of universes, with cumulativity: Type : Type1, Type1 : Type2, ...
18− * Pattern matching letrec binding
19− * (primitive types defined externally)
20−
21− Some technical stuff:
22− * Typechecker is kept as simple as possible
23− - no unification, just a checker for incomplete terms.
24− * We have a simple collection of tactics which we use to elaborate source
25− programs with implicit syntax into fully explicit terms.
26−-}
27−
2833data Option = TTypeInTType
2934 | CheckConv
3035 deriving Eq
@@ -318,10 +323,11 @@ instance Pretty Raw where
318323deriving instance Binary Raw
319324!-}
320325
321−data Binder b = Lam { binderTy :: b }
326+-- | All binding forms are represented in a unform fashion.
327+data Binder b = Lam { binderTy :: b {-^ type annotation for bound variable-}}
322328 | Pi { binderTy :: b }
323329 | Let { binderTy :: b,
324− binderVal :: b }
330+ binderVal :: b {-^ value for bound variable-}}
325331 | NLet { binderTy :: b,
326332 binderVal :: b }
327333 | Hole { binderTy :: b}
@@ -435,15 +441,16 @@ instance Eq NameType where
435441 TCon _ a == TCon _ b = (a == b) -- ignore tag
436442 _ == _ = False
437443
438−data TT n = P NameType n (TT n) -- embed type
439− | V Int
440− | Bind n (Binder (TT n)) (TT n)
441− | App (TT n) (TT n) -- function, function type, arg
442− | Constant Const
443− | Proj (TT n) Int -- argument projection; runtime only
444− | Erased
445− | Impossible -- special case for totality checking
446− | TType UExp
444+-- | Terms in the core language
445+data TT n = P NameType n (TT n) -- ^ named references
446+ | V Int -- ^ a resolved de Bruijn-indexed variable
447+ | Bind n (Binder (TT n)) (TT n) -- ^ a binding
448+ | App (TT n) (TT n) -- ^ function, function type, arg
449+ | Constant Const -- ^ constant
450+ | Proj (TT n) Int -- ^ argument projection; runtime only
451+ | Erased -- ^ an erased term
452+ | Impossible -- ^ special case for totality checking
453+ | TType UExp -- ^ the type of types at some level
447454 deriving (Ord, Functor)
448455{-!
449456deriving instance Binary TT
@@ -501,6 +508,9 @@ instance Eq n => Eq (TT n) where
501508
502509-- * A few handy operations on well typed terms:
503510
511+-- | A term is injective iff it is a data constructor, type constructor,
512+-- constant, the type Type, pi-binding, or an application of an injective
513+-- term.
504514isInjective :: TT n -> Bool
505515isInjective (P (DCon _ _) _ _) = True
506516isInjective (P (TCon _ _) _ _) = True