126 lines
3.3 KiB
Idris
126 lines
3.3 KiB
Idris
module Quox.Definition
|
|
|
|
import public Quox.No
|
|
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 : Pred q) 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
|
|
toElim : Definition' q _ -> Maybe $ Elim q d n
|
|
toElim def = pure $ (!def.term).get :# def.type.get
|
|
|
|
|
|
public export
|
|
0 IsZero : IsQty q => Pred $ Definition q
|
|
IsZero g = IsZero g.qty
|
|
|
|
public export %inline
|
|
isZero : (p : IsQty q) => Dec1 $ Definition.IsZero @{p}
|
|
isZero g = isZero g.qty
|
|
|
|
|
|
public export
|
|
0 Definitions' : (q : Type) -> Pred q -> 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)
|
|
|
|
public export
|
|
0 HasDefs : (q : Type) -> IsQty q => (Type -> Type) -> Type
|
|
HasDefs q = HasDefs' q IsGlobal
|
|
|
|
|
|
public export %inline
|
|
lookupElim : forall isGlobal.
|
|
Name -> Definitions' q isGlobal -> Maybe (Elim q d n)
|
|
lookupElim x defs = toElim !(lookup x defs)
|
|
|
|
|
|
parameters {0 isGlobal : _} (defs : Definitions' q isGlobal)
|
|
namespace Term
|
|
public export %inline
|
|
isRedex : Term q d n -> Bool
|
|
isRedex = isRedex $ \x => lookupElim x defs
|
|
|
|
public export
|
|
0 IsRedex, NotRedex : Pred $ Term q d n
|
|
IsRedex = So . isRedex
|
|
NotRedex = No . isRedex
|
|
|
|
namespace Elim
|
|
public export %inline
|
|
isRedex : Elim q d n -> Bool
|
|
isRedex = isRedex $ \x => lookupElim x defs
|
|
|
|
public export
|
|
0 IsRedex, NotRedex : Pred $ Elim q d n
|
|
IsRedex = So . isRedex
|
|
NotRedex = No . isRedex
|
|
|
|
public export
|
|
0 NonRedexElim, NonRedexTerm :
|
|
(q : Type) -> (d, n : Nat) -> {isGlobal : Pred q} ->
|
|
Definitions' q isGlobal -> Type
|
|
NonRedexElim q d n defs = Subset (Elim q d n) (NotRedex defs)
|
|
NonRedexTerm q d n defs = Subset (Term q d n) (NotRedex defs)
|
|
|
|
parameters {0 isGlobal : _} (defs : Definitions' q isGlobal)
|
|
namespace Term
|
|
export %inline
|
|
whnf : Term q d n -> NonRedexTerm q d n defs
|
|
whnf = whnf $ \x => lookupElim x defs
|
|
|
|
namespace Elim
|
|
export %inline
|
|
whnf : Elim q d n -> NonRedexElim q d n defs
|
|
whnf = whnf $ \x => lookupElim x defs
|