Created
October 4, 2022 22:42
-
-
Save TOTBWF/0ea18b7393384d6f6ee78ec7dc3b217b to your computer and use it in GitHub Desktop.
A simple Agda tactic that just uses the first valid thing in scope.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module 1Lab.Reflection.Duh where | |
open import 1Lab.Reflection | |
open import 1Lab.Prelude | |
open import Data.List | |
open import Data.Nat | |
private | |
try-all : Term → Nat → Telescope → TC Term | |
try-all goal _ [] = typeError $ strErr "Couldn't find anything!" ∷ [] | |
try-all goal n ((_ , tp) ∷ tele) = | |
catchTC (unify goal (Arg.unarg tp) >> pure (var n [])) (try-all goal (suc n) tele) | |
macro | |
duh! : Term → TC ⊤ | |
duh! hole = do | |
ctx ← getContext | |
goal ← inferType hole | |
tm ← try-all goal 0 ctx | |
unify hole tm | |
test : Nat → List Nat → Nat | |
test x y = duh! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment