quox/src/Quox/Typing.idr

106 lines
1.9 KiB
Idris
Raw Normal View History

2021-12-23 13:05:50 -05:00
module Quox.Typing
import public Quox.Syntax
import public Quox.Context
2022-04-23 18:21:30 -04:00
import public Quox.Equal
2021-12-23 13:05:50 -05:00
import Data.Nat
2022-04-23 18:21:30 -04:00
import public Data.SortedMap
2021-12-23 13:05:50 -05:00
import Control.Monad.Reader
import Control.Monad.State
%default total
2022-02-26 19:28:19 -05:00
2021-12-23 13:05:50 -05:00
public export
data DContext : Nat -> Type where
DNil : DContext 0
DBind : DContext d -> DContext (S d)
DEq : Dim d -> Dim d -> DContext d -> DContext d
public export
TContext : Nat -> Nat -> Type
TContext d = Context (Term d)
public export
QContext : Nat -> Type
2022-04-27 15:58:09 -04:00
QContext = Context' Qty
2021-12-23 13:05:50 -05:00
public export
QOutput : Nat -> Type
2022-04-27 15:58:09 -04:00
QOutput = QContext
2021-12-23 13:05:50 -05:00
public export
record Global where
constructor MkGlobal
type, term : forall d, n. Term d n
public export
Globals : Type
Globals = SortedMap Name Global
public export
record TyContext (d, n : Nat) where
constructor MkTyContext
globals : Globals
dctx : DContext d
tctx : TContext d n
qctx : QContext n
%name TyContext ctx
namespace TContext
export
pushD : TContext d n -> TContext (S d) n
pushD tel = map (/// shift 1) tel
namespace TyContext
export
2022-04-27 15:58:09 -04:00
extendTy : Term d n -> Qty -> TyContext d n -> TyContext d (S n)
extendTy s rho = {tctx $= (:< s), qctx $= (:< rho)}
2021-12-23 13:05:50 -05:00
export
extendDim : TyContext d n -> TyContext (S d) n
extendDim = {dctx $= DBind, tctx $= pushD}
export
eqDim : Dim d -> Dim d -> TyContext d n -> TyContext d n
eqDim p q = {dctx $= DEq p q}
namespace QOutput
export
(+) : QOutput n -> QOutput n -> QOutput n
(+) = zipWith (+)
export
(*) : Qty -> QOutput n -> QOutput n
(*) pi = map (pi *)
export
zero : {n : Nat} -> QOutput n
zero = pure Zero
2022-04-23 18:21:30 -04:00
public export
2022-04-27 15:58:09 -04:00
CheckResult : Nat -> Type
CheckResult = QOutput
2022-04-23 18:21:30 -04:00
public export
record InferResult d n where
constructor InfRes
type : Term d n
2022-04-27 15:58:09 -04:00
qout : QOutput n
2022-04-23 18:21:30 -04:00
public export
data Error
= NotInScope Name
| ExpectedTYPE (Term d n)
| ExpectedPi (Term d n)
| BadUniverse Universe Universe