@@ -165,7 +165,25 @@ elab ist info pattern opts fn tm
165-- ++ "\nproblems " ++ show ps
165-- ++ "\nproblems " ++ show ps
166-- ++ "\n-----------\n") $
166-- ++ "\n-----------\n") $
167-- trace ("ELAB " ++ show t') $
167-- trace ("ELAB " ++ show t') $
168+ let fc = fileFC "Force"
169+ handleError forceErr
168− elab' ina t'
170+ (elab' ina t')
171+ (elab' ina (PApp fc (PRef fc (sUN "Force"))
172+ [pimp (sUN "a") Placeholder True,
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
170 local f = do e <- get_env
188 local f = do e <- get_env
171 return (f `elem` map fst e)
189 return (f `elem` map fst e)
@@ -243,6 +261,7 @@ elab ist info pattern opts fn tm
243 ctxt <- get_context
261 ctxt <- get_context
244 let (tc, _) = unApply ty
262 let (tc, _) = unApply ty
245 let as' = pruneByType tc ctxt as
263 let as' = pruneByType tc ctxt as
264+-- trace (show as ++ "\n ==> " ++ showSep ", " (map showTmImpls as')) $
246 tryAll (zip (map (elab' ina) as') (map showHd as'))
265 tryAll (zip (map (elab' ina) as') (map showHd as'))
247 where showHd (PApp _ (PRef _ n) _) = show n
266 where showHd (PApp _ (PRef _ n) _) = show n
248 showHd (PRef _ n) = show n
267 showHd (PRef _ n) = show n
@@ -438,7 +457,9 @@ elab ist info pattern opts fn tm
438 let (ns', eargs) = unzip $
457 let (ns', eargs) = unzip $
439 sortBy cmpArg (zip ns args)
458 sortBy cmpArg (zip ns args)
440 elabArgs ist (ina || not isinf, guarded, inty)
459 elabArgs ist (ina || not isinf, guarded, inty)
441− [] fc False f ns' (map (\x -> (lazyarg x, getTm x)) eargs)
462+ (map (\x -> (lazyarg x, getTm x)) eargs)
443 ivs' <- get_instances
464 ivs' <- get_instances
444 -- Attempt to resolve any type classes which have 'complete' types,
465 -- Attempt to resolve any type classes which have 'complete' types,
@@ -610,17 +631,20 @@ elab ist info pattern opts fn tm
610 getFC d x = d
631 getFC d x = d
612 insertLazy :: PTerm -> ElabD PTerm
633 insertLazy :: PTerm -> ElabD PTerm
613−-- insertLazy t | pattern = return t
614 insertLazy t@(PApp _ (PRef _ (UN l)) _) | l == txt "Delay" = return t
634 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
615 insertLazy t =
637 insertLazy t =
616 do ty <- goal
638 do ty <- goal
617 env <- get_env
639 env <- get_env
618 let (tyh, _) = unApply (normalise (tt_ctxt ist) env ty)
640 let (tyh, _) = unApply (normalise (tt_ctxt ist) env ty)
641+ let tries = if pattern then [t, mkDelay t] else [mkDelay t, t]
619 case tyh of
642 case tyh of
620 P _ (UN l) _ | l == txt "Lazy"
643 P _ (UN l) _ | l == txt "Lazy"
621− -> return (PAlternative False [t, mkDelay t])
644+ -> return (PAlternative False tries)
622 _ -> return t
645 _ -> return t
647+ mkDelay (PAlternative b xs) = PAlternative b (map mkDelay xs)
624 mkDelay t = let fc = fileFC "Delay" in
648 mkDelay t = let fc = fileFC "Delay" in
625 addImpl ist (PApp fc (PRef fc (sUN "Delay")) [pexp t])
649 addImpl ist (PApp fc (PRef fc (sUN "Delay")) [pexp t])
@@ -650,15 +674,16 @@ elab ist info pattern opts fn tm
651 -> Name -- ^ Name of the function being applied
675 -> Name -- ^ Name of the function being applied
652 -> [(Name, Name)] -- ^ (Argument Name, Hole Name)
676 -> [(Name, Name)] -- ^ (Argument Name, Hole Name)
677+ -> Bool -- ^ under a 'force'
653 -> [(Bool, PTerm)] -- ^ (Laziness, argument)
678 -> [(Bool, PTerm)] -- ^ (Laziness, argument)
654 -> ElabD ()
679 -> ElabD ()
655− elabArgs ist ina failed fc retry f [] _
680+ elabArgs ist ina failed fc retry f [] force _
656-- | retry = let (ns, ts) = unzip (reverse failed) in
681-- | retry = let (ns, ts) = unzip (reverse failed) in
657-- elabArgs ina [] False ns ts
682-- elabArgs ina [] False ns ts
658 | otherwise = return ()
683 | otherwise = return ()
659− elabArgs ist ina failed fc r f (n:ns) ((_, Placeholder) : args)
684+ elabArgs ist ina failed fc r f (n:ns) force ((_, Placeholder) : args)
660− = elabArgs ist ina failed fc r f ns args
685+ = elabArgs ist ina failed fc r f ns force args
661− elabArgs ist ina failed fc r f ((argName, holeName):ns) ((lazy, t) : args)
686+ elabArgs ist ina failed fc r f ((argName, holeName):ns) force ((lazy, t) : args)
662 | lazy && not pattern
687 | lazy && not pattern
663 = elabArg argName holeName (PApp bi (PRef bi (sUN "lazy"))
688 = elabArg argName holeName (PApp bi (PRef bi (sUN "lazy"))
664 [pimp (sUN "a") Placeholder True,
689 [pimp (sUN "a") Placeholder True,
@@ -668,12 +693,15 @@ elab ist info pattern opts fn tm
668 reflectFunctionErrors ist f argName $
693 reflectFunctionErrors ist f argName $
669 do hs <- get_holes
694 do hs <- get_holes
670 tm <- get_term
695 tm <- get_term
696+ -- No coercing under an explicit Force (or it can Force/Delay
698+ let elab = if force then elab' else elabE
671 failed' <- -- trace (show (n, t, hs, tm)) $
699 failed' <- -- trace (show (n, t, hs, tm)) $
672 -- traceWhen (not (null cs)) (show ty ++ "\n" ++ showImp True t) $
700 -- traceWhen (not (null cs)) (show ty ++ "\n" ++ showImp True t) $
673 case holeName `elem` hs of
701 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
675 False -> return failed
703 False -> return failed
676− elabArgs ist ina failed fc r f ns args
704+ elabArgs ist ina failed fc r f ns force args
678-- | Perform error reflection for function applicaitons with specific error handlers
706-- | Perform error reflection for function applicaitons with specific error handlers
679reflectFunctionErrors :: IState -> Name -> Name -> ElabD a -> ElabD a
707reflectFunctionErrors :: IState -> Name -> Name -> ElabD a -> ElabD a