@@ -19,7 +19,7 @@ import Idris.Core.Unify
1919import Idris.Core.DeepSeq
2020
2121import Control.DeepSeq
22−import Control.Monad.State
22+import Control.Monad.State.Strict
2323import Data.Char
2424import Data.List
2525import Debug.Trace
@@ -48,7 +48,7 @@ proofFail :: Elab' aux a -> Elab' aux a
4848proofFail e = do s <- get
4949 case runStateT e s of
5050 OK (a, s') -> do put s'
51− return a
51+ return $! a
5252 Error err -> lift $ Error (ProofSearchFail err)
5353
5454explicit :: Name -> Elab' aux ()
@@ -77,7 +77,7 @@ getNameFrom n = do (ES (p, a) s e) <- get
7777 then MN (next+500) x
7878 else MN (next+100) x
7979 NS (UN x) s -> MN (next+100) x
80− return n'
80+ return $! n'
8181
8282setNextName :: Elab' aux ()
8383setNextName = do env <- get_env
@@ -98,7 +98,7 @@ errAt :: String -> Name -> Elab' aux a -> Elab' aux a
9898errAt thing n elab = do s <- get
9999 case runStateT elab s of
100100 OK (a, s') -> do put s'
101− return a
101+ return $! a
102102 Error (At f e) ->
103103 lift $ Error (At f (Elaborating thing n e))
104104 Error e -> lift $ Error (Elaborating thing n e)
@@ -107,7 +107,7 @@ erun :: FC -> Elab' aux a -> Elab' aux a
107107erun f elab = do s <- get
108108 case runStateT elab s of
109109 OK (a, s') -> do put s'
110− return a
110+ return $! a
111111 Error (ProofSearchFail (At f e))
112112 -> lift $ Error (ProofSearchFail (At f e))
113113 Error (At f e) -> lift $ Error (At f e)
@@ -125,7 +125,7 @@ initElaborator = newProof
125125elaborate :: Context -> Name -> Type -> aux -> Elab' aux a -> TC (a, String)
126126elaborate ctxt n ty d elab = do let ps = initElaborator n ctxt ty
127127 (a, ES ps' str _) <- runElab d elab ps
128− return (a, str)
128+ return $! (a, str)
129129
130130force_term :: Elab' aux ()
131131force_term = do ES (ps, a) l p <- get
@@ -137,7 +137,7 @@ updateAux f = do ES (ps, a) l p <- get
137137
138138getAux :: Elab' aux aux
139139getAux = do ES (ps, a) _ _ <- get
140− return a
140+ return $! a
141141
142142unifyLog :: Bool -> Elab' aux ()
143143unifyLog log = do ES (ps, a) l p <- get
@@ -146,14 +146,14 @@ unifyLog log = do ES (ps, a) l p <- get
146146processTactic' t = do ES (p, a) logs prev <- get
147147 (p', log) <- lift $ processTactic t p
148148 put (ES (p', a) (logs ++ log) prev)
149− return ()
149+ return $! ()
150150
151151-- Some handy gadgets for pulling out bits of state
152152
153153-- get the global context
154154get_context :: Elab' aux Context
155155get_context = do ES p _ _ <- get
156− return (context (fst p))
156+ return $! (context (fst p))
157157
158158-- update the context
159159-- (should only be used for adding temporary definitions or all sorts of
@@ -165,7 +165,7 @@ set_context ctxt = do ES (p, a) logs prev <- get
165165-- get the proof term
166166get_term :: Elab' aux Term
167167get_term = do ES p _ _ <- get
168− return (pterm (fst p))
168+ return $! (pterm (fst p))
169169
170170-- get the proof term
171171update_term :: (Term -> Term) -> Elab' aux ()
@@ -180,24 +180,24 @@ get_env = do ES p _ _ <- get
180180
181181get_holes :: Elab' aux [Name]
182182get_holes = do ES p _ _ <- get
183− return (holes (fst p))
183+ return $! (holes (fst p))
184184
185185get_probs :: Elab' aux Fails
186186get_probs = do ES p _ _ <- get
187− return (problems (fst p))
187+ return $! (problems (fst p))
188188
189189-- get the current goal type
190190goal :: Elab' aux Type
191191goal = do ES p _ _ <- get
192192 b <- lift $ goalAtFocus (fst p)
193− return (binderTy b)
193+ return $! (binderTy b)
194194
195195-- Get the guess at the current hole, if there is one
196196get_guess :: Elab' aux Type
197197get_guess = do ES p _ _ <- get
198198 b <- lift $ goalAtFocus (fst p)
199199 case b of
200− Guess t v -> return v
200+ Guess t v -> return $! v
201201 _ -> fail "Not a guess"
202202
203203-- typecheck locally
@@ -205,22 +205,22 @@ get_type :: Raw -> Elab' aux Type
205205get_type tm = do ctxt <- get_context
206206 env <- get_env
207207 (val, ty) <- lift $ check ctxt env tm
208− return (finalise ty)
208+ return $! (finalise ty)
209209
210210get_type_val :: Raw -> Elab' aux (Term, Type)
211211get_type_val tm = do ctxt <- get_context
212212 env <- get_env
213213 (val, ty) <- lift $ check ctxt env tm
214− return (finalise val, finalise ty)
214+ return $! (finalise val, finalise ty)
215215
216216-- get holes we've deferred for later definition
217217get_deferred :: Elab' aux [Name]
218218get_deferred = do ES p _ _ <- get
219− return (deferred (fst p))
219+ return $! (deferred (fst p))
220220
221221checkInjective :: (Term, Term, Term) -> Elab' aux ()
222222checkInjective (tm, l, r) = do ctxt <- get_context
223− if isInj ctxt tm then return ()
223+ if isInj ctxt tm then return $! ()
224224 else lift $ tfail (NotInjective tm l r)
225225 where isInj ctxt (P _ n _)
226226 | isConName n ctxt = True
@@ -233,7 +233,7 @@ checkInjective (tm, l, r) = do ctxt <- get_context
233233-- get instance argument names
234234get_instances :: Elab' aux [Name]
235235get_instances = do ES p _ _ <- get
236− return (instances (fst p))
236+ return $! (instances (fst p))
237237
238238-- given a desired hole name, return a unique hole name
239239unique_hole = unique_hole' False
@@ -251,13 +251,13 @@ unique_hole' reusable n
251251-- then return n
252252-- else getNameFrom n
253253-- _ -> getNameFrom n
254− return $ uniqueNameCtxt (context (fst p)) n nouse
254+ return $! uniqueNameCtxt (context (fst p)) n nouse
255255 ES (p, a) s u <- get
256256 case n' of
257257 MN i _ -> when (i >= nextname p) $
258258 put (ES (p { nextname = i + 1 }, a) s u)
259− _ -> return ()
260− return n'
259+ _ -> return $! ()
260+ return $! n'
261261 where
262262 bound_in (Bind n b sc) = n : bi b ++ bound_in sc
263263 where
@@ -273,7 +273,7 @@ elog str = do ES p logs prev <- get
273273
274274getLog :: Elab' aux String
275275getLog = do ES p logs _ <- get
276− return logs
276+ return $! logs
277277
278278-- The primitives, from ProofState
279279
@@ -357,9 +357,9 @@ patvar n = do env <- get_env
357357 hs <- get_holes
358358 if (n `elem` map fst env) then do apply (Var n) []; solve
359359 else do n' <- case n of
360− UN _ -> return n
360+ UN _ -> return $! n
361361 MN _ _ -> unique_hole n
362− NS _ _ -> return n
362+ NS _ _ -> return $! n
363363 processTactic' (PatVar n')
364364
365365patbind :: Name -> Elab' aux ()
@@ -399,7 +399,7 @@ reorder_claims n = processTactic' (Reorder n)
399399qed :: Elab' aux Term
400400qed = do processTactic' QED
401401 ES p _ _ <- get
402− return (pterm (fst p))
402+ return $! (pterm (fst p))
403403
404404undo :: Elab' aux ()
405405undo = processTactic' Undo
@@ -420,7 +420,7 @@ prepare_apply fn imps =
420420-- case claims of
421421-- [] -> return ()
422422-- (h : _) -> reorder_claims h
423− return claims
423+ return $! claims
424424 where
425425 mkClaims (Bind n' (Pi t_in) sc) (i : is) claims hs =
426426 do let t = rebind hs t_in
@@ -431,7 +431,7 @@ prepare_apply fn imps =
431431 claim n (forget t)
432432 when i (movelast n)
433433 mkClaims sc' is (n : claims) hs
434− mkClaims t [] claims _ = return (reverse claims)
434+ mkClaims t [] claims _ = return $! (reverse claims)
435435 mkClaims _ _ _ _
436436 | Var n <- fn
437437 = do ctxt <- get_context
@@ -462,13 +462,10 @@ match_apply = apply' match_fill
462462apply' :: (Raw -> Elab' aux ()) -> Raw -> [(Bool, Int)] -> Elab' aux [Name]
463463apply' fillt fn imps =
464464 do args <- prepare_apply fn (map fst imps)
465− env <- get_env
466− g <- goal
467465 -- _Don't_ solve the arguments we're specifying by hand.
468466 -- (remove from unified list before calling end_unify)
469467 -- HMMM: Actually, if we get it wrong, the typechecker will complain!
470468 -- so do nothing
471− ptm <- get_term
472469 hs <- get_holes
473470 ES (p, a) s prev <- get
474471 let dont = head hs : dontunify p ++
@@ -484,12 +481,9 @@ apply' fillt fn imps =
484481 put (ES (p { dontunify = dont, unified = (n, unify),
485482 notunified = notunify ++ notunified p }, a) s prev)
486483 fillt (raw_apply fn (map Var args))
487− ptm <- get_term
488− g <- goal
489484-- trace ("Goal " ++ show g ++ "\n" ++ show (fn, imps, unify) ++ "\n" ++ show ptm) $
490485 end_unify
491− ptm <- get_term
492− return (map (updateUnify unify) args)
486+ return $! (map (updateUnify unify) args)
493487 where updateUnify us n = case lookup n us of
494488 Just (P _ t _) -> t
495489 _ -> n
@@ -503,7 +497,7 @@ apply2 fn elabs =
503497 let (n, hs) = unified p
504498 end_unify
505499 solve
506− where elabArgs [] [] = return ()
500+ where elabArgs [] [] = return $! ()
507501 elabArgs (n:ns) (Just e:es) = do focus n; e
508502 elabArgs ns es
509503 elabArgs (n:ns) (_:es) = elabArgs ns es
@@ -534,18 +528,18 @@ apply_elab n args =
534528 let sc' = instantiate (P Bound n t) sc
535529 claim n (forget t)
536530 case i of
537− Nothing -> return ()
531+ Nothing -> return $! ()
538532 Just _ -> -- don't solve by unification as there is an explicit value
539533 do ES (p, a) s prev <- get
540534 put (ES (p { dontunify = n : dontunify p }, a) s prev)
541535 doClaims sc' is ((n, i) : claims)
542− doClaims t [] claims = return (reverse claims)
536+ doClaims t [] claims = return $! (reverse claims)
543537 doClaims _ _ _ = fail $ "Wrong number of arguments for " ++ show n
544538
545539 elabClaims failed r []
546− | null failed = return ()
540+ | null failed = return $! ()
547541 | otherwise = if r then elabClaims [] False failed
548− else return ()
542+ else return $! ()
549543 elabClaims failed r ((n, Nothing) : xs) = elabClaims failed r xs
550544 elabClaims failed r (e@(n, Just (_, elaboration)) : xs)
551545 | r = try (do ES p _ _ <- get
@@ -563,7 +557,7 @@ checkPiGoal :: Name -> Elab' aux ()
563557checkPiGoal n
564558 = do g <- goal
565559 case g of
566− Bind _ (Pi _) _ -> return ()
560+ Bind _ (Pi _) _ -> return $! ()
567561 _ -> do a <- getNameFrom (MN 0 "pargTy")
568562 b <- getNameFrom (MN 0 "pretTy")
569563 f <- getNameFrom (MN 0 "pf")
@@ -623,7 +617,7 @@ no_errors tac
623617 ((x,y,env,err) : _) ->
624618 let env' = map (\(x, b) -> (x, binderTy b)) env in
625619 lift $ tfail $ CantUnify False x y err env' 0
626− else return ()
620+ else return $! ()
627621
628622-- Try a tactic, if it fails, try another
629623try :: Elab' aux a -> Elab' aux a -> Elab' aux a
@@ -635,10 +629,10 @@ try' t1 t2 proofSearch
635629 ps <- get_probs
636630 case prunStateT 999999 False ps t1 s of
637631 OK ((v, _), s') -> do put s'
638− return v
632+ return $! v
639633 Error e1 -> if recoverableErr e1 then
640634 do case runStateT t2 s of
641− OK (v, s') -> do put s'; return v
635+ OK (v, s') -> do put s'; return $! v
642636 Error e2 -> if score e1 >= score e2
643637 then lift (tfail e1)
644638 else lift (tfail e2)
@@ -675,8 +669,8 @@ tryAll xs = tryAll' [] 999999 (cantResolve, 0) (map fst xs)
675669 case prunStateT pmax True ps x s of
676670 OK ((v, newps), s') ->
677671 do let cs' = if (newps < pmax)
678− then [do put s'; return v]
679− else (do put s'; return v) : cs
672+ then [do put s'; return $! v]
673+ else (do put s'; return $! v) : cs
680674 tryAll' cs' newps f xs
681675 Error err -> do put s
682676 if (score err) < 100