quox/lib/Quox/Definition.idr

51 lines
1.1 KiB
Idris
Raw Normal View History

2022-08-22 04:17:08 -04:00
module Quox.Definition
import public Quox.Syntax
import public Data.SortedMap
import public Control.Monad.State
public export
record AnyTerm where
constructor T
2023-01-08 09:07:01 -05:00
get : forall d, n. Term d n
2022-08-22 04:17:08 -04:00
public export
record Definition where
constructor MkDef'
2023-01-08 09:44:20 -05:00
qty : Qty
type : AnyTerm
term : Maybe AnyTerm
{auto 0 qtyGlobal : IsGlobal qty}
2022-08-22 04:17:08 -04:00
public export %inline
2023-01-08 09:44:20 -05:00
mkDef : (qty : Qty) -> (0 _ : IsGlobal qty) =>
(type, term : forall d, n. Term d n) -> Definition
mkDef qty type term = MkDef' {qty, type = T type, term = Just (T term)}
2022-08-22 04:17:08 -04:00
public export %inline
2023-01-08 09:44:20 -05:00
mkAbstract : (qty : Qty) -> (0 _ : IsGlobal qty) =>
2022-08-22 04:17:08 -04:00
(type : forall d, n. Term d n) -> Definition
2023-01-08 09:44:20 -05:00
mkAbstract qty type = MkDef' {qty, type = T type, term = Nothing}
2022-08-22 04:17:08 -04:00
public export %inline
(.type0) : Definition -> Term 0 0
2023-01-08 09:07:01 -05:00
g.type0 = g.type.get
2022-08-22 04:17:08 -04:00
public export %inline
(.term0) : Definition -> Maybe (Term 0 0)
2023-01-08 09:07:01 -05:00
g.term0 = map (\t => t.get) g.term
2022-08-22 04:17:08 -04:00
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