quox/lib/Quox/Definition.idr

93 lines
2.3 KiB
Idris
Raw Normal View History

2022-08-22 04:17:08 -04:00
module Quox.Definition
import public Quox.No
2022-08-22 04:17:08 -04:00
import public Quox.Syntax
import public Data.SortedMap
2023-03-31 13:23:30 -04:00
import Control.Eff
2023-01-08 14:44:25 -05:00
import Decidable.Decidable
2022-08-22 04:17:08 -04:00
public export
data DefBody q =
Concrete (Term q 0 0)
| Postulate
namespace DefBody
public export
(.term0) : DefBody q -> Maybe (Term q 0 0)
(Concrete t).term0 = Just t
(Postulate).term0 = Nothing
2022-08-22 04:17:08 -04:00
public export
2023-01-20 19:41:21 -05:00
record Definition' q (isGlobal : Pred q) where
constructor MkDef
qty : q
type0 : Term q 0 0
body0 : DefBody q
2023-01-08 14:44:25 -05:00
{auto 0 qtyGlobal : isGlobal qty}
public export
0 Definition : (q : Type) -> IsQty q => Type
Definition q = Definition' q IsGlobal
2022-08-22 04:17:08 -04:00
public export %inline
mkPostulate : IsQty q => (qty : q) -> (0 _ : IsGlobal qty) =>
(type0 : Term q 0 0) -> Definition q
mkPostulate qty type0 = MkDef {qty, type0, body0 = Postulate}
2022-08-22 04:17:08 -04:00
2023-03-13 14:33:09 -04:00
public export %inline
mkDef : IsQty q => (qty : q) -> (0 _ : IsGlobal qty) =>
(type0, term0 : Term q 0 0) -> Definition q
mkDef qty type0 term0 = MkDef {qty, type0, body0 = Concrete term0}
2022-08-22 04:17:08 -04:00
public export %inline
2023-01-08 14:44:25 -05:00
(.qtyP) : forall q, isGlobal. Definition' q isGlobal -> Subset q isGlobal
2022-08-22 04:17:08 -04:00
g.qtyP = Element g.qty g.qtyGlobal
parameters {d, n : Nat}
public export %inline
(.type) : Definition' q _ -> Term q d n
g.type = g.type0 // shift0 d // shift0 n
2023-01-20 19:41:21 -05:00
public export %inline
(.term) : Definition' q _ -> Maybe (Term q d n)
g.term = g.body0.term0 <&> \t => t // shift0 d // shift0 n
public export %inline
toElim : Definition' q _ -> Maybe $ Elim q d n
toElim def = pure $ !def.term :# def.type
2023-01-20 19:41:21 -05:00
public export
0 IsZero : IsQty q => Pred $ Definition q
IsZero g = IsZero g.qty
2022-08-22 04:17:08 -04:00
public export %inline
2023-01-20 19:41:21 -05:00
isZero : (p : IsQty q) => Dec1 $ Definition.IsZero @{p}
isZero g = isZero g.qty
2023-01-08 14:44:25 -05:00
public export
2023-01-20 19:41:21 -05:00
0 Definitions' : (q : Type) -> Pred q -> Type
2023-01-08 14:44:25 -05:00
Definitions' q isGlobal = SortedMap Name $ Definition' q isGlobal
2022-08-22 04:17:08 -04:00
public export
2023-01-08 14:44:25 -05:00
0 Definitions : (q : Type) -> IsQty q => Type
Definitions q = Definitions' q IsGlobal
public export
2023-03-31 13:23:30 -04:00
0 DefsReader' : (q : Type) -> (q -> Type) -> Type -> Type
DefsReader' q isGlobal = Reader (Definitions' q isGlobal)
2023-01-08 14:44:25 -05:00
2023-01-20 19:41:30 -05:00
public export
2023-03-31 13:23:30 -04:00
0 DefsReader : (q : Type) -> IsQty q => Type -> Type
DefsReader q = DefsReader' q IsGlobal
public export %inline
lookupElim : forall isGlobal. {d, n : Nat} ->
Name -> Definitions' q isGlobal -> Maybe (Elim q d n)
lookupElim x defs = toElim !(lookup x defs)