@@ -265,7 +265,7 @@ consCB _ γ (NonRec x e)
265265 where
266266 checkLetHole =
267267 do
268- isItHole <- detectTypedHole γ e
268+ let isItHole = detectTypedHole e
269269 case isItHole of
270270 Just (srcSpan, var) -> do
271271 traceM $ Text. printf " HOLE DETECTED LET %s: %s: %s" (show x) (show var) (show srcSpan)
@@ -346,21 +346,42 @@ addPToEnv γ π
346346 = do γπ <- γ += (" addSpec1" , pname π, pvarRType π)
347347 foldM (+=) γπ [(" addSpec2" , x, ofRSort t) | (t, x, _) <- pargs π]
348348
349+ detectTypedHole :: CoreExpr -> Maybe (RealSrcSpan , Var )
350+ detectTypedHole e =
351+ case stripTicks e of
352+ Var x | isVarHole x ->
353+ case lastTick e of
354+ Just (SourceNote src _) -> Just (src, x)
355+ _ -> Nothing
356+ _ -> Nothing
357+
358+ -- Remove Initial App and sequent Tick nodes from an expression.
359+ stripTicks :: CoreExpr -> CoreExpr
360+ stripTicks (App (Tick _ e) _) = stripTicks e
361+ stripTicks (Tick _ e) = stripTicks e
362+ stripTicks e = e
363+
364+ -- Traverse the expression to get the last Tick information.
365+ lastTick :: Expr b -> Maybe CoreTickish
366+ lastTick (Tick t e) =
367+ case lastTick e of
368+ Just t' -> Just t'
369+ Nothing -> Just t
370+ lastTick (App e a) =
371+ case lastTick a of
372+ Just ta -> Just ta
373+ Nothing -> lastTick e
374+ lastTick _ = Nothing
375+
376+ -- A helper to check if the variable name indicates a typed hole.
377+ isVarHole :: Var -> Bool
378+ isVarHole x = isHoleStr (F. symbolString (F. symbol x))
379+ where
380+ isHoleStr s =
381+ case break (== ' .' ) s of
382+ (_, ' .' : rest) -> rest == " hole"
383+ _ -> False
349384
350- detectTypedHole :: CGEnv -> CoreExpr -> CG (Maybe (RealSrcSpan , Var ))
351- detectTypedHole _ (App (Tick genTick (Var x)) _) | isVarHole x
352- = return (Just (getSrcSpanFromTick, x))
353- where
354- getSrcSpanFromTick =
355- case genTick of
356- SourceNote src _ -> src
357- _ -> panic Nothing " Not a Source Note"
358- isStrHole s =
359- case break (== ' .' ) s of
360- (_, ' .' : rest) -> rest == " hole"
361- _ -> False
362- isVarHole = isStrHole . F. symbolString . F. symbol
363- detectTypedHole _ _ = return Nothing -- NOT A TYPED HOLE
364385--------------------------------------------------------------------------------
365386-- | Bidirectional Constraint Generation: CHECKING -----------------------------
366387--------------------------------------------------------------------------------
@@ -444,7 +465,7 @@ cconsE' γ e t
444465 addC (SubC γ te' t) (" cconsE: " ++ " \n t = " ++ showpp t ++ " \n te = " ++ showpp te ++ GM. showPpr e)
445466 where
446467 maybeAddHole = do
447- isItHole <- detectTypedHole γ e
468+ let isItHole = detectTypedHole e
448469 case isItHole of
449470 Just (srcSpan, x) -> do
450471 traceM $ Text. printf " HOLE DETECTED CHECKING: %s" (show x)
@@ -579,7 +600,7 @@ consE γ e'@(App _ _) =
579600 return t
580601 where
581602 synthesizeWithHole = do
582- isItHole <- detectTypedHole γ e'
603+ let isItHole = detectTypedHole e'
583604 t <- consEApp γ e'
584605 traceM $ Text. printf " SYNTHESIZING EXPRESSION: %s\n TYPE: [ %s ]\n " (showpp e') (show t)
585606 _ <- case isItHole of
0 commit comments