@@ -31,9 +31,23 @@ idrisInit = IState emptyContext [] emptyContext "" []
3131-- global state (hence the IO inner monad).
3232type Idris a = StateT IState IO a
3333
34+getContext :: Idris Context
35+getContext = do i <- get; return (tt_ctxt i)
36+
37+setContext :: Context -> Idris ()
38+setContext ctxt = do i <- get; put (i { tt_ctxt = ctxt } )
39+
40+updateContext :: (Context -> Context) -> Idris ()
41+updateContext f = do i <- get; put (i { tt_ctxt = f (tt_ctxt i) } )
42+
3443iputStrLn :: String -> Idris ()
3544iputStrLn = lift.putStrLn
3645
46+tclift :: Show a => TC a -> Idris a
47+tclift tc = case tc of
48+ OK v -> return v
49+ err -> fail (show err)
50+
3751setOpt :: IOption -> Bool -> Idris ()
3852setOpt o True = do i <- get
3953 put (i { idris_options = nub (o : idris_options i) })
@@ -143,6 +157,8 @@ showImp impl tm = se 10 tm where
143157 | impl = bracket p 2 $ "{" ++ show n ++ " : " ++ se 10 ty ++
144158 "} -> " ++ se 10 sc
145159 | otherwise = se 10 sc
160+ se p (PApp (PRef f) _ [])
161+ | not impl = show f
146162 se p (PApp (PRef op@(UN [f:_])) _ [l, r])
147163 | not impl && not (isAlpha f)
148164 = bracket p 1 $ se 1 l ++ " " ++ show op ++ " " ++ se 1 r
@@ -221,10 +237,15 @@ implicitise ist tm
221237addImpl :: IState -> PTerm -> PTerm
222238addImpl ist ptm = ai [] ptm
223239 where
240+ ai env (PRef f) = aiFn env (PRef f) [] []
241+ ai env (PApp (PRef f) is es)
242+ = let is' = map (\ (n, tm) -> (n, ai env tm)) is
243+ es' = map (ai env) es in
244+ aiFn env (PRef f) is' es'
224245 ai env (PApp f is es) = let f' = ai env f
225− is' = map (\ (n, tm) -> (n, ai env tm)) is
246+ is' = map (\ (n, tm) -> (n, ai env tm)) is
226247 es' = map (ai env) es in
227− aiFn env f is' es'
248+ aiFn env f' is' es'
228249 ai env (PLam n ty sc) = let ty' = ai env ty
229250 sc' = ai (n:env) sc in
230251 PLam n ty' sc'
@@ -236,9 +257,12 @@ addImpl ist ptm = ai [] ptm
236257
237258 aiFn env (PRef f) is es | not (f `elem` env)
238259 = case lookupCtxt f (idris_implicits ist) of
239− Just ns -> PApp (PRef f) (insertImpl ns is) es
240− Nothing -> PApp (PRef f) is es
241− aiFn env f is es = PApp f is es
260+ Just ns -> pApp (PRef f) (insertImpl ns is) es
261+ Nothing -> pApp (PRef f) is es
262+ aiFn env f is es = pApp f is es
263+
264+ pApp f [] [] = f
265+ pApp f is es = PApp f is es
242266
243267 insertImpl [] given = []
244268 insertImpl (n:ns) given