2021-12-23 13:05:50 -05:00
|
|
|
module Quox.Typing
|
|
|
|
|
|
|
|
import public Quox.Syntax
|
|
|
|
import public Quox.Context
|
2022-08-22 04:17:08 -04:00
|
|
|
import public Quox.Definition
|
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
|
2022-08-22 23:43:23 -04:00
|
|
|
import Generics.Derive
|
|
|
|
|
|
|
|
%hide TT.Name
|
|
|
|
%default total
|
|
|
|
%language ElabReflection
|
2021-12-23 13:05:50 -05:00
|
|
|
|
|
|
|
%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 TyContext (d, n : Nat) where
|
|
|
|
constructor MkTyContext
|
|
|
|
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
|
2022-04-07 21:47:11 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
2022-08-22 23:43:23 -04:00
|
|
|
public export
|
|
|
|
data EqMode = Equal | Sub
|
|
|
|
%runElab derive "EqMode" [Generic, Meta, Eq, Ord, DecEq, Show]
|
|
|
|
|
|
|
|
|
2022-04-23 18:21:30 -04:00
|
|
|
public export
|
|
|
|
data Error
|
2022-08-22 23:43:23 -04:00
|
|
|
= ExpectedTYPE (Term d n)
|
2022-04-23 18:21:30 -04:00
|
|
|
| ExpectedPi (Term d n)
|
2022-05-06 15:23:58 -04:00
|
|
|
| BadUniverse Universe Universe
|
2022-08-22 23:43:23 -04:00
|
|
|
|
|
|
|
| ClashT EqMode (Term d n) (Term d n)
|
|
|
|
| ClashU EqMode Universe Universe
|
|
|
|
| ClashQ Qty Qty
|
|
|
|
| NotInScope Name
|