2022-08-22 04:17:08 -04:00
|
|
|
module Quox.Definition
|
|
|
|
|
2023-01-22 18:53:34 -05:00
|
|
|
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
|
|
|
|
|
|
|
|
2023-03-13 14:31:05 -04:00
|
|
|
public export
|
2023-04-01 13:16:43 -04:00
|
|
|
data DefBody =
|
|
|
|
Concrete (Term 0 0)
|
2023-03-13 14:31:05 -04:00
|
|
|
| Postulate
|
|
|
|
|
2023-03-25 17:41:30 -04:00
|
|
|
namespace DefBody
|
|
|
|
public export
|
2023-04-01 13:16:43 -04:00
|
|
|
(.term0) : DefBody -> Maybe (Term 0 0)
|
2023-03-25 17:41:30 -04:00
|
|
|
(Concrete t).term0 = Just t
|
|
|
|
(Postulate).term0 = Nothing
|
|
|
|
|
|
|
|
|
2022-08-22 04:17:08 -04:00
|
|
|
public export
|
2023-04-01 13:16:43 -04:00
|
|
|
record Definition where
|
2023-03-13 14:31:05 -04:00
|
|
|
constructor MkDef
|
2023-04-01 13:16:43 -04:00
|
|
|
qty : GQty
|
|
|
|
type0 : Term 0 0
|
|
|
|
body0 : DefBody
|
2022-08-22 04:17:08 -04:00
|
|
|
|
|
|
|
public export %inline
|
2023-04-01 13:16:43 -04:00
|
|
|
mkPostulate : GQty -> (type0 : Term 0 0) -> Definition
|
2023-03-25 17:41:30 -04:00
|
|
|
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
|
2023-04-01 13:16:43 -04:00
|
|
|
mkDef : GQty -> (type0, term0 : Term 0 0) -> Definition
|
2023-03-25 17:41:30 -04:00
|
|
|
mkDef qty type0 term0 = MkDef {qty, type0, body0 = Concrete term0}
|
2023-03-13 14:31:05 -04:00
|
|
|
|
2022-08-22 04:17:08 -04:00
|
|
|
|
2023-03-25 17:41:30 -04:00
|
|
|
parameters {d, n : Nat}
|
|
|
|
public export %inline
|
2023-04-01 13:16:43 -04:00
|
|
|
(.type) : Definition -> Term d n
|
2023-03-25 17:41:30 -04:00
|
|
|
g.type = g.type0 // shift0 d // shift0 n
|
2023-01-20 19:41:21 -05:00
|
|
|
|
2023-03-25 17:41:30 -04:00
|
|
|
public export %inline
|
2023-04-01 13:16:43 -04:00
|
|
|
(.term) : Definition -> Maybe (Term d n)
|
2023-03-25 17:41:30 -04:00
|
|
|
g.term = g.body0.term0 <&> \t => t // shift0 d // shift0 n
|
|
|
|
|
|
|
|
public export %inline
|
2023-04-01 13:16:43 -04:00
|
|
|
toElim : Definition -> Maybe $ Elim d n
|
2023-03-25 17:41:30 -04:00
|
|
|
toElim def = pure $ !def.term :# def.type
|
2023-01-22 18:53:34 -05:00
|
|
|
|
|
|
|
|
2022-08-22 04:17:08 -04:00
|
|
|
public export %inline
|
2023-04-01 13:16:43 -04:00
|
|
|
isZero : Definition -> Bool
|
|
|
|
isZero g = g.qty.fst == Zero
|
2023-01-08 14:44:25 -05:00
|
|
|
|
|
|
|
|
2023-04-17 17:58:24 -04:00
|
|
|
public export
|
2023-04-18 16:55:23 -04:00
|
|
|
data DefEnvTag = DEFS
|
2023-04-17 17:58:24 -04:00
|
|
|
|
2023-01-08 14:44:25 -05:00
|
|
|
public export
|
2023-04-01 13:16:43 -04:00
|
|
|
Definitions : Type
|
|
|
|
Definitions = SortedMap Name Definition
|
2023-01-08 14:44:25 -05:00
|
|
|
|
2023-01-20 19:41:30 -05:00
|
|
|
public export
|
2023-04-01 13:16:43 -04:00
|
|
|
0 DefsReader : Type -> Type
|
2023-04-17 17:58:24 -04:00
|
|
|
DefsReader = ReaderL DEFS Definitions
|
2023-01-22 18:53:34 -05:00
|
|
|
|
2023-04-17 17:58:24 -04:00
|
|
|
export
|
|
|
|
defs : Has DefsReader fs => Eff fs Definitions
|
|
|
|
defs = askAt DEFS
|
|
|
|
|
|
|
|
|
2023-04-18 16:55:23 -04:00
|
|
|
public export %inline
|
|
|
|
lookupElim : {d, n : Nat} -> Name -> Definitions -> Maybe (Elim d n)
|
|
|
|
lookupElim x defs = toElim !(lookup x defs)
|