Skip to content

Commit

Permalink
MonadTC: add getInstance + findInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
omelkonian committed Nov 3, 2023
1 parent bdf468f commit 13f4a6f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
17 changes: 16 additions & 1 deletion Class/MonadTC.agda
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ record MonadTC (M : ∀ {f} → Set f → Set f)
isMacro : Name M Bool
debugPrint : String List ErrorPart M ⊤
runSpeculative : M (A × Bool) M A
getInstances : Meta M (List Term)

instance _ = Functor-M
open MonadError me
Expand Down Expand Up @@ -351,5 +352,19 @@ module _ {M : ∀ {f} → Set f → Set f}
runWithHole hole tac
return hole

-- Finding all instance candidates of a given type.
findInstances : Type M (List Term)
findInstances ty = runAndReset $ do
just m findMeta <$> newMeta ty
where _ error1 "[findInstances] newMeta did not produce meta-variable!"
getInstances m
where
open import Data.Maybe using (_<∣>_)
findMeta = λ where
(pi (arg _ ty) (abs _ t)) findMeta ty <∣> findMeta t
(lam _ (abs _ t)) findMeta t
(meta m _) just m
_ nothing

MonadTC-TC : MonadTC R.TC ⦃ Monad-TC ⦄ ⦃ MonadError-TC ⦄
MonadTC-TC = record { R; R' using (quoteωTC; withReconstructed; onlyReduceDefs; dontReduceDefs) }
MonadTC-TC = record { R; R' using (quoteωTC; withReconstructed; onlyReduceDefs; dontReduceDefs; getInstances) }
3 changes: 3 additions & 0 deletions Reflection/TCI.agda
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,8 @@ module MonadTCI where
runSpeculative : TC (A × Bool) TC A
runSpeculative = R.runSpeculative ∘_

getInstances : Meta TC (List Term)
getInstances = liftTC1 R'.getInstances

MonadTC-TCI : MonadTC TC ⦃ Monad-TC ⦄ ⦃ MonadError-TC ⦄
MonadTC-TCI = record { MonadTCI }
6 changes: 3 additions & 3 deletions Reflection/Utils.agda
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@ module _ (f : ℕ → ℕ) where

mapFreeVarsᶜ : (Clause Clause)
mapFreeVarsᶜ b = λ where
-- clause : (tel : List (Σ String λ _ Arg Type)) (ps : List (Arg Pattern)) (t : Term) Clause
(clause tel ps t) clause (mapFreeVarsᵗ b tel) (mapFreeVarsᵖ∗ b ps) (mapFreeVars (length tel + b) t)
-- absurd-clause : (tel : List (Σ String λ _ Arg Type)) (ps : List (Arg Pattern)) Clause
(clause tel ps t) clause (mapFreeVarsᵗ b tel) (mapFreeVarsᵖ∗ b ps)
(mapFreeVars (length tel + b) t)
(absurd-clause tel ps) absurd-clause (mapFreeVarsᵗ b tel) (mapFreeVarsᵖ∗ b ps)
mapFreeVarsᶜ∗ : (List Clause List Clause)
mapFreeVarsᶜ∗ b = λ where
Expand Down Expand Up @@ -240,6 +239,7 @@ apply⋯ is n = def n $ remove-iArgs $
map (λ{ (n , arg i _) arg i (♯ (length is ∸ suc (toℕ n)))}) (zip (allFin $ length is) is)

-- ** records

mkRecord : List (Name × Term) Term
mkRecord fs = pat-lam (map (λ where (fn , e) clause [] [ vArg (proj fn) ] e) fs) []

Expand Down

0 comments on commit 13f4a6f

Please sign in to comment.