@@ -4,6 +4,7 @@ open import Reflection
44 renaming (visible to expl; hidden to impl; instance′ to inst;
55 relevant to rel; irrelevant to irr; pi to absPi; lam to absLam; def to appDef)
66 hiding (var; con; meta; _≟_) public
7+ open import Agda.Builtin.Reflection using (withNormalisation) public
78open Term using () renaming (var to appVar; con to appCon; meta to appMeta) public
89open Pattern using () renaming (var to patVar; con to patCon) public
910open Literal using () renaming (meta to litMeta) public
@@ -435,11 +436,13 @@ _·_ = sate _$_
435436unshift′ : Term -> Term
436437unshift′ t = explLam "_" t · sate tt₀
437438
439+ -- A note for myself: `foldℕ (sate lsuc) (sate lzero) n` is not `reify n`:
440+ -- it's damn `lsuc` -- not `suc`.
438441termLevelOf : Term -> Maybe Term
439442termLevelOf (sort (set t)) = just t
440443termLevelOf (sort (lit n)) = just (foldℕ (sate lsuc) (sate lzero) n)
441444termLevelOf (sort unknown) = just unknown
442- termLevelOf _ = nothing
445+ termLevelOf _ = nothing
443446
444447instance
445448 TermReify : Reify Term
@@ -499,7 +502,6 @@ instance
499502 go [] tt = sate tt₀
500503 go (x ∷ xs) (y , ys) = sate _,_ (reify {{bReify}} y) (go xs ys)
501504
502-
503505toTuple : List Term -> Term
504506toTuple = foldr₁ (sate _,_) (sate tt₀)
505507
@@ -528,15 +530,21 @@ normalize (pi s (arg i a) b) =
528530 pi s ∘ arg i <$> normalize a <*> extendContext (arg i a) (normalize b)
529531normalize t = normalise t
530532
533+ getNormType : Name -> TC Type
534+ getNormType = getType >=> normalize
535+
536+ inferNormType : Term -> TC Type
537+ inferNormType = inferType >=> normalize
538+
531539getData : Name -> TC (Data Type)
532- getData d = getType d >>= λ ab -> getDefinition d >>= λ
540+ getData d = getNormType d >>= λ ab -> getDefinition d >>= λ
533541 { (data-type p cs) ->
534- mapM (λ c -> _,_ c ∘ dropPis p <$> (getType c >>= normalize) ) cs >>= λ mans ->
542+ mapM (λ c -> _,_ c ∘ dropPis p <$> getNormType c ) cs >>= λ mans ->
535543 case takePis p ab ⊗ (dropPis p ab ⊗ (mapM (uncurry λ c ma -> flip _,_ c <$> ma) mans)) of λ
536544 { nothing -> panic "getData: data"
537545 ; (just (a , b , acs)) -> return ∘ uncurry (packData d a b) $ splitList acs
538546 }
539- ; (record′ c) -> getType c >>= dropPis (countPis ab) >>> λ
547+ ; (record′ c) -> getNormType c >>= dropPis (countPis ab) >>> λ
540548 { nothing -> panic "getData: record"
541549 ; (just a′) -> return $ packData d (initType ab) (lastType ab) (a′ ∷ []) (c , tt)
542550 }
@@ -545,4 +553,7 @@ getData d = getType d >>= λ ab -> getDefinition d >>= λ
545553
546554macro
547555 TypeOf : Term -> Term -> TC _
548- TypeOf t ?r = inferType t >>= unify ?r
556+ TypeOf t ?r = inferNormType t >>= unify ?r
557+
558+ runTC : ∀ {α} {A : Set α} -> TC A -> Term -> TC _
559+ runTC a ?r = bindTC a quoteTC >>= unify ?r
0 commit comments