quox/lib/Quox/Definition.idr

68 lines
1.5 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
2023-04-01 13:16:43 -04:00
data DefBody =
Concrete (Term 0 0)
| Postulate
namespace DefBody
public export
2023-04-01 13:16:43 -04:00
(.term0) : DefBody -> Maybe (Term 0 0)
(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
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
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
mkDef qty type0 term0 = MkDef {qty, type0, body0 = Concrete term0}
2022-08-22 04:17:08 -04:00
parameters {d, n : Nat}
public export %inline
2023-04-01 13:16:43 -04:00
(.type) : Definition -> Term d n
g.type = g.type0 // shift0 d // shift0 n
2023-01-20 19:41:21 -05:00
public export %inline
2023-04-01 13:16:43 -04:00
(.term) : Definition -> Maybe (Term d n)
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
toElim def = pure $ !def.term :# def.type
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
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
DefsReader = Reader Definitions
public export %inline
2023-04-01 13:16:43 -04:00
lookupElim : {d, n : Nat} -> Name -> Definitions -> Maybe (Elim d n)
lookupElim x defs = toElim !(lookup x defs)