module Quox.Definition import public Quox.Syntax import public Data.SortedMap import public Control.Monad.Reader import Decidable.Decidable public export record AnyTerm q where constructor T get : forall d, n. Term q d n public export record Definition' q (isGlobal : q -> Type) where constructor MkDef' 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 public export %inline mkDef : IsQty q => (qty : q) -> (0 _ : IsGlobal qty) => (type, term : forall d, n. Term q d n) -> Definition q mkDef qty type term = MkDef' {qty, type = T type, term = Just (T term)} public export %inline mkAbstract : IsQty q => (qty : q) -> (0 _ : IsGlobal qty) => (type : forall d, n. Term q d n) -> Definition q mkAbstract qty type = MkDef' {qty, type = T type, term = Nothing} public export %inline (.type0) : Definition' q _ -> Term q 0 0 g.type0 = g.type.get public export %inline (.term0) : Definition' q _ -> Maybe (Term q 0 0) g.term0 = map (\t => t.get) g.term public export %inline (.qtyP) : forall q, isGlobal. Definition' q isGlobal -> Subset q isGlobal g.qtyP = Element g.qty g.qtyGlobal public export %inline 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 public export 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