quox/lib/Quox/Definition.idr

68 lines
1.8 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
2023-01-08 14:44:25 -05:00
import public Control.Monad.Reader
import Decidable.Decidable
2022-08-22 04:17:08 -04:00
public export
2023-01-08 14:44:25 -05:00
record AnyTerm q where
2022-08-22 04:17:08 -04:00
constructor T
2023-01-08 14:44:25 -05:00
get : forall d, n. Term q d n
2022-08-22 04:17:08 -04:00
public export
2023-01-08 14:44:25 -05:00
record Definition' q (isGlobal : q -> Type) where
2022-08-22 04:17:08 -04:00
constructor MkDef'
2023-01-08 14:44:25 -05:00
qty : q
type : AnyTerm q
term : Maybe $ AnyTerm q
{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
2023-01-08 14:44:25 -05:00
mkDef : IsQty q => (qty : q) -> (0 _ : IsGlobal qty) =>
(type, term : forall d, n. Term q d n) -> Definition q
2023-01-08 09:44:20 -05:00
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 14:44:25 -05:00
mkAbstract : IsQty q => (qty : q) -> (0 _ : IsGlobal qty) =>
(type : forall d, n. Term q d n) -> Definition q
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
2023-01-08 14:44:25 -05:00
(.type0) : Definition' q _ -> Term q 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
2023-01-08 14:44:25 -05:00
(.term0) : Definition' q _ -> Maybe (Term q 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
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
public export %inline
2023-01-08 14:44:25 -05:00
isZero : IsQty q => Definition q -> Bool
isZero g = isYes $ isZero g.qty
public export
0 Definitions' : (q : Type) -> (q -> Type) -> Type
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
0 HasDefs' : (q : Type) -> (q -> Type) -> (Type -> Type) -> Type
HasDefs' q isGlobal = MonadReader (Definitions' q isGlobal)
0 HasDefs : (q : Type) -> IsQty q => (Type -> Type) -> Type
HasDefs q = HasDefs' q IsGlobal