add Definitions module

This commit is contained in:
rhiannon morris 2022-08-22 10:17:08 +02:00
parent 413c454898
commit 44778825c2
5 changed files with 57 additions and 14 deletions

View file

@ -15,7 +15,7 @@ import Control.Monad.Identity
infixl 5 :<
||| a sequence of bindings under an existing context. each successive element
||| has one more bound variable, which correspond to all previous elements
||| as well as the global context.
||| as well as the surrounding context.
public export
data Telescope : (tm : Nat -> Type) -> (from, to : Nat) -> Type where
Lin : Telescope tm from from
@ -26,7 +26,7 @@ public export
Telescope' : (a : Type) -> (from, to : Nat) -> Type
Telescope' a = Telescope (\_ => a)
||| a global context is actually just a telescope over no existing bindings
||| a top level context is actually just a telescope over no existing bindings
public export
Context : (tm : Nat -> Type) -> (len : Nat) -> Type
Context tm len = Telescope tm 0 len

52
lib/Quox/Definition.idr Normal file
View file

@ -0,0 +1,52 @@
module Quox.Definition
import public Quox.Syntax
import public Data.SortedMap
import public Control.Monad.State
public export
record AnyTerm where
constructor T
def : forall d, n. Term d n
public export
record Definition where
constructor MkDef'
qty : Qty
0 qtyGlobal : IsGlobal qty
type : AnyTerm
term : Maybe AnyTerm
public export %inline
MkDef : (qty : Qty) -> (0 qtyGlobal : IsGlobal qty) =>
(type, term : forall d, n. Term d n) -> Definition
MkDef {qty, type, term} =
MkDef' {qty, qtyGlobal = %search, type = T type, term = Just (T term)}
public export %inline
MkAbstract : (qty : Qty) -> (0 qtyGlobal : IsGlobal qty) =>
(type : forall d, n. Term d n) -> Definition
MkAbstract {qty, type} =
MkDef' {qty, qtyGlobal = %search, type = T type, term = Nothing}
public export %inline
(.type0) : Definition -> Term 0 0
g.type0 = g.type.def
public export %inline
(.term0) : Definition -> Maybe (Term 0 0)
g.term0 = map (\t => t.def) g.term
public export %inline
(.qtyP) : Definition -> Subset Qty IsGlobal
g.qtyP = Element g.qty g.qtyGlobal
public export %inline
isZero : Definition -> Bool
isZero g = g.qty == Zero
public export
Definitions : Type
Definitions = SortedMap Name Definition

View file

@ -1,6 +1,7 @@
module Quox.Equal
import public Quox.Syntax
import public Quox.Definition
import Control.Monad.Either
import Generics.Derive

View file

@ -3,6 +3,7 @@ module Quox.Typing
import public Quox.Syntax
import public Quox.Context
import public Quox.Equal
import public Quox.Definition
import Data.Nat
import public Data.SortedMap
@ -31,18 +32,6 @@ QOutput : Nat -> Type
QOutput = QContext
public export
record Global where
constructor MkGlobal
qty : Qty
0 qtyGlobal : IsGlobal qty
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

View file

@ -26,6 +26,7 @@ modules =
Quox.Syntax.Term.Subst,
Quox.Syntax.Universe,
Quox.Syntax.Var,
Quox.Definition,
Quox.Token,
Quox.Lexer,
Quox.Parser,