@@ -3,13 +3,8 @@
3||| eventual Prelude inclusion.
3||| eventual Prelude inclusion.
4module Pruviloj.Core
4module Pruviloj.Core
7−import Language.Reflection.Elab
8import Language.Reflection.Utils
6import Language.Reflection.Utils
10−data Infer : Type where
11− MkInfer : (a : Type) -> a -> Infer
13||| Run something for effects, throwing away the return value
8||| Run something for effects, throwing away the return value
14ignore : Functor f => f a -> f ()
9ignore : Functor f => f a -> f ()
15ignore x = map (const ()) x
10ignore x = map (const ()) x
@@ -85,11 +80,11 @@ intros = do g <- snd <$> getGoal
86||| Run a tactic inside of a particular hole, if it still exists. If
81||| Run a tactic inside of a particular hole, if it still exists. If
87||| it has been solved, do nothing.
82||| it has been solved, do nothing.
88−inHole : TTName -> Elab () -> Elab ()
83+inHole : TTName -> Elab a -> Elab (Maybe a)
89inHole h todo =
84inHole h todo =
90− when (h `elem` !getHoles) $
85+ if (h `elem` !getHoles)
91− do focus h
86+ then do focus h; Just <$> todo
92− todo
87+ else return Nothing
94||| Restrict a polymorphic type to () for contexts where it doesn't
89||| Restrict a polymorphic type to () for contexts where it doesn't
95||| matter. This is nice for sticking `debug` in a context where
90||| matter. This is nice for sticking `debug` in a context where
@@ -142,3 +137,26 @@ bindPat = do compute
142 case g of
137 case g of
143 Bind n (PVTy _) _ => patbind n
138 Bind n (PVTy _) _ => patbind n
144 _ => fail [TermPart g, TextPart "isn't looking for a pattern."]
139 _ => fail [TermPart g, TextPart "isn't looking for a pattern."]
141+||| The underlying implementation type for the inferType operator.
142+data Infer : Type where
143+ MkInfer : (a : Type) -> a -> Infer
145+||| Run a tactic script in a context where the type of the resulting
146+||| expression must be solvable via unification. Return the term and
149+||| @ tac a tactic script that will be run with focus on the hole
150+||| whose type is to be inferred.
152+inferType : (tac : Elab ()) -> Elab (TT, TT)
154+ case fst !(runElab `(Infer) (startInfer *> tac)) of
155+ `(MkInfer ~ty ~tm) => return (tm, ty)
156+ _ => fail [TextPart "Not infer"]
158+ startInfer : Elab ()
159+ startInfer = do [_, (_, tmH)] <- apply (Var `{MkInfer}) [(True, 0), (False, 1)]
160+ | err => fail [TextPart "Type inference failure"]