@@ -165,7 +165,25 @@ elab ist info pattern opts fn tm
165165-- ++ "\nproblems " ++ show ps
166166-- ++ "\n-----------\n") $
167167-- trace ("ELAB " ++ show t') $
168− elab' ina t'
168+ let fc = fileFC "Force"
169+ handleError forceErr
170+ (elab' ina t')
171+ (elab' ina (PApp fc (PRef fc (sUN "Force"))
172+ [pimp (sUN "a") Placeholder True,
173+ pexp ct])) True
174+
175+ forceErr (CantUnify _ t t' _ _ _)
176+ | (P _ (UN ht) _, _) <- unApply t,
177+ ht == txt "Lazy" = True
178+ forceErr (CantUnify _ t t' _ _ _)
179+ | (P _ (UN ht) _, _) <- unApply t',
180+ ht == txt "Lazy" = True
181+ forceErr (InfiniteUnify _ t _)
182+ | (P _ (UN ht) _, _) <- unApply t,
183+ ht == txt "Lazy" = True
184+ forceErr (Elaborating _ _ t) = forceErr t
185+ forceErr (At _ t) = forceErr t
186+ forceErr t = False
169187
170188 local f = do e <- get_env
171189 return (f `elem` map fst e)
@@ -243,6 +261,7 @@ elab ist info pattern opts fn tm
243261 ctxt <- get_context
244262 let (tc, _) = unApply ty
245263 let as' = pruneByType tc ctxt as
264+-- trace (show as ++ "\n ==> " ++ showSep ", " (map showTmImpls as')) $
246265 tryAll (zip (map (elab' ina) as') (map showHd as'))
247266 where showHd (PApp _ (PRef _ n) _) = show n
248267 showHd (PRef _ n) = show n
@@ -438,7 +457,9 @@ elab ist info pattern opts fn tm
438457 let (ns', eargs) = unzip $
439458 sortBy cmpArg (zip ns args)
440459 elabArgs ist (ina || not isinf, guarded, inty)
441− [] fc False f ns' (map (\x -> (lazyarg x, getTm x)) eargs)
460+ [] fc False f ns'
461+ (f == sUN "Force")
462+ (map (\x -> (lazyarg x, getTm x)) eargs)
442463 solve
443464 ivs' <- get_instances
444465 -- Attempt to resolve any type classes which have 'complete' types,
@@ -610,17 +631,20 @@ elab ist info pattern opts fn tm
610631 getFC d x = d
611632
612633 insertLazy :: PTerm -> ElabD PTerm
613−-- insertLazy t | pattern = return t
614634 insertLazy t@(PApp _ (PRef _ (UN l)) _) | l == txt "Delay" = return t
635+ insertLazy t@(PApp _ (PRef _ (UN l)) _) | l == txt "Force" = return t
636+ insertLazy (PCoerced t) = return t
615637 insertLazy t =
616638 do ty <- goal
617639 env <- get_env
618640 let (tyh, _) = unApply (normalise (tt_ctxt ist) env ty)
641+ let tries = if pattern then [t, mkDelay t] else [mkDelay t, t]
619642 case tyh of
620643 P _ (UN l) _ | l == txt "Lazy"
621− -> return (PAlternative False [t, mkDelay t])
644+ -> return (PAlternative False tries)
622645 _ -> return t
623646 where
647+ mkDelay (PAlternative b xs) = PAlternative b (map mkDelay xs)
624648 mkDelay t = let fc = fileFC "Delay" in
625649 addImpl ist (PApp fc (PRef fc (sUN "Delay")) [pexp t])
626650
@@ -650,15 +674,16 @@ elab ist info pattern opts fn tm
650674 -> Bool
651675 -> Name -- ^ Name of the function being applied
652676 -> [(Name, Name)] -- ^ (Argument Name, Hole Name)
677+ -> Bool -- ^ under a 'force'
653678 -> [(Bool, PTerm)] -- ^ (Laziness, argument)
654679 -> ElabD ()
655− elabArgs ist ina failed fc retry f [] _
680+ elabArgs ist ina failed fc retry f [] force _
656681-- | retry = let (ns, ts) = unzip (reverse failed) in
657682-- elabArgs ina [] False ns ts
658683 | otherwise = return ()
659− elabArgs ist ina failed fc r f (n:ns) ((_, Placeholder) : args)
660− = elabArgs ist ina failed fc r f ns args
661− elabArgs ist ina failed fc r f ((argName, holeName):ns) ((lazy, t) : args)
684+ elabArgs ist ina failed fc r f (n:ns) force ((_, Placeholder) : args)
685+ = elabArgs ist ina failed fc r f ns force args
686+ elabArgs ist ina failed fc r f ((argName, holeName):ns) force ((lazy, t) : args)
662687 | lazy && not pattern
663688 = elabArg argName holeName (PApp bi (PRef bi (sUN "lazy"))
664689 [pimp (sUN "a") Placeholder True,
@@ -668,12 +693,15 @@ elab ist info pattern opts fn tm
668693 reflectFunctionErrors ist f argName $
669694 do hs <- get_holes
670695 tm <- get_term
696+ -- No coercing under an explicit Force (or it can Force/Delay
697+ -- recursively!)
698+ let elab = if force then elab' else elabE
671699 failed' <- -- trace (show (n, t, hs, tm)) $
672700 -- traceWhen (not (null cs)) (show ty ++ "\n" ++ showImp True t) $
673701 case holeName `elem` hs of
674− True -> do focus holeName; elabE ina t; return failed
702+ True -> do focus holeName; elab ina t; return failed
675703 False -> return failed
676− elabArgs ist ina failed fc r f ns args
704+ elabArgs ist ina failed fc r f ns force args
677705
678706-- | Perform error reflection for function applicaitons with specific error handlers
679707reflectFunctionErrors :: IState -> Name -> Name -> ElabD a -> ElabD a