on master help sign in
Laziness annotations
commit1155e7952727e454e2732a929ee630ae4bf91287 authorEdwin Brady <eb@cs.st-andrews.ac.uk> dateWed 26 Oct 2011, 16:54 (15 years ago) parent6638f64
6 files changed+166−132
lib/builtins.idr+4−1 src/Idris/AbsSyntax.hs+50−39 src/Idris/Compiler.hs+3 src/Idris/Delaborate.hs+6−6 src/Idris/ElabDecls.hs+32−24 src/Idris/Parser.hs+71−62
lib/builtins.idr+4−1
@@ -7,6 +7,9 @@ getSigIdx (Exists a v) = a;
77getSigVal : {P : a -> Set} -> (s : Sigma a P) -> P (getSigIdx s);
88getSigVal (Exists a v) = v;
99
10+lazy : a -> a;
11+lazy x = x; -- compiled specially
12+
1013id : a -> a;
1114id x = x;
1215
@@ -28,7 +31,7 @@ f $ a = f a;
2831
2932data Bool = False | True;
3033
31−boolElim : (x:Bool) -> a -> a -> a;
34+boolElim : (x:Bool) -> |(t : a) -> |(f : a) -> a;
3235boolElim True t e = t;
3336boolElim False t e = e;
3437
src/Idris/AbsSyntax.hs+50−39
@@ -33,11 +33,12 @@ data IState = IState { tt_ctxt :: Context,
3333 idris_name :: Int,
3434 idris_metavars :: [Name],
3535 syntax_rules :: [Syntax],
36+ syntax_keywords :: [String],
3637 imported :: [FilePath],
3738 idris_prims :: [(Name, ([E.Name], E.Term))]
3839 }
3940
40−idrisInit = IState emptyContext [] emptyContext "" defaultOpts 6 [] [] [] []
41+idrisInit = IState emptyContext [] emptyContext "" defaultOpts 6 [] [] [] [] []
4142
4243-- The monad for the main REPL - reading and processing files and updating
4344-- global state (hence the IO inner monad).
@@ -139,7 +140,11 @@ data FixDecl = Fix Fixity String
139140instance Ord FixDecl where
140141 compare (Fix x _) (Fix y _) = compare (prec x) (prec y)
141142
142−data Plicity = Imp | Exp deriving (Show, Eq)
143+-- Mark bindings with their explicitness, and laziness
144+data Plicity = Imp Bool | Exp Bool deriving (Show, Eq)
145+
146+impl = Imp False
147+expl = Exp False
143148
144149data PDecl' t = PFix FC Fixity [String] -- fixity declaration
145150 | PTy FC Name t -- type declaration
@@ -205,10 +210,13 @@ data PDo = DoExp FC PTerm
205210 | DoLet FC Name PTerm
206211 deriving Eq
207212
208−data PArg' t = PImp { pname :: Name, getTm :: t }
209− | PExp { getTm :: t }
213+data PArg' t = PImp { lazyarg :: Bool, pname :: Name, getTm :: t }
214+ | PExp { lazyarg :: Bool, getTm :: t }
210215 deriving (Show, Eq, Functor)
211216
217+pimp = PImp False
218+pexp = PExp False
219+
212220type PArg = PArg' PTerm
213221
214222-- Syntactic sugar info (TODO: namespaces, modules)
@@ -275,12 +283,12 @@ showDImp impl (PDatadecl n ty cons)
275283
276284getImps :: [PArg] -> [(Name, PTerm)]
277285getImps [] = []
278−getImps (PImp n tm : xs) = (n, tm) : getImps xs
286+getImps (PImp _ n tm : xs) = (n, tm) : getImps xs
279287getImps (_ : xs) = getImps xs
280288
281289getExps :: [PArg] -> [PTerm]
282290getExps [] = []
283−getExps (PExp tm : xs) = tm : getExps xs
291+getExps (PExp _ tm : xs) = tm : getExps xs
284292getExps (_ : xs) = getExps xs
285293
286294getAll :: [PArg] -> [PTerm]
@@ -293,13 +301,15 @@ showImp impl tm = se 10 tm where
293301 se p (PLam n ty sc) = bracket p 2 $ "\\ " ++ show n ++ " => " ++ show sc
294302 se p (PLet n ty v sc) = bracket p 2 $ "let " ++ show n ++ " = " ++ se 10 v ++
295303 " in " ++ se 10 sc
296− se p (PPi Exp n ty sc)
304+ se p (PPi (Exp l) n ty sc)
297305 | n `elem` allNamesIn sc = bracket p 2 $
298− "(" ++ show n ++ " : " ++ se 10 ty ++
306+ if l then "|(" else "(" ++
307+ show n ++ " : " ++ se 10 ty ++
299308 ") -> " ++ se 10 sc
300309 | otherwise = bracket p 2 $ se 0 ty ++ " -> " ++ se 10 sc
301− se p (PPi Imp n ty sc)
302− | impl = bracket p 2 $ "{" ++ show n ++ " : " ++ se 10 ty ++
310+ se p (PPi (Imp l) n ty sc)
311+ | impl = bracket p 2 $ if l then "|{" else "{" ++
312+ show n ++ " : " ++ se 10 ty ++
303313 "} -> " ++ se 10 sc
304314 | otherwise = se 10 sc
305315 se p (PApp _ (PRef _ f) [])
@@ -369,11 +379,11 @@ inferTy = MN 0 "__Infer"
369379inferCon = MN 0 "__infer"
370380inferDecl = PDatadecl inferTy
371381 PSet
372− [(inferCon, PPi Imp (MN 0 "A") PSet (
373− PPi Exp (MN 0 "a") (PRef bi (MN 0 "A"))
382+ [(inferCon, PPi impl (MN 0 "A") PSet (
383+ PPi expl (MN 0 "a") (PRef bi (MN 0 "A"))
374384 (PRef bi inferTy)), bi)]
375385
376−infTerm t = PApp bi (PRef bi inferCon) [PImp (MN 0 "A") Placeholder, PExp t]
386+infTerm t = PApp bi (PRef bi inferCon) [pimp (MN 0 "A") Placeholder, pexp t]
377387infP = P (TCon 6 0) inferTy (Set 0)
378388
379389getInferTerm, getInferType :: Term -> Term
@@ -397,12 +407,12 @@ falseDecl = PDatadecl falseTy PSet []
397407pairTy = MN 0 "__Pair"
398408pairCon = MN 0 "__MkPair"
399409pairDecl = PDatadecl pairTy (piBind [(n "A", PSet), (n "B", PSet)] PSet)
400− [(pairCon, PPi Imp (n "A") PSet (
401− PPi Imp (n "B") PSet (
402− PPi Exp (n "a") (PRef bi (n "A")) (
403− PPi Exp (n "b") (PRef bi (n "B"))
404− (PApp bi (PRef bi pairTy) [PExp (PRef bi (n "A")),
405− PExp (PRef bi (n "B"))])))), bi)]
410+ [(pairCon, PPi impl (n "A") PSet (
411+ PPi impl (n "B") PSet (
412+ PPi expl (n "a") (PRef bi (n "A")) (
413+ PPi expl (n "b") (PRef bi (n "B"))
414+ (PApp bi (PRef bi pairTy) [pexp (PRef bi (n "A")),
415+ pexp (PRef bi (n "B"))])))), bi)]
406416 where n a = MN 0 a
407417
408418eqTy = UN ["="]
@@ -410,12 +420,12 @@ eqCon = UN ["refl"]
410420eqDecl = PDatadecl eqTy (piBind [(n "a", PSet), (n "b", PSet),
411421 (n "x", PRef bi (n "a")), (n "y", PRef bi (n "b"))]
412422 PSet)
413− [(eqCon, PPi Imp (n "a") PSet (
414− PPi Imp (n "x") (PRef bi (n "a"))
415− (PApp bi (PRef bi eqTy) [PImp (n "a") Placeholder,
416− PImp (n "b") Placeholder,
417− PExp (PRef bi (n "x")),
418− PExp (PRef bi (n "x"))])), bi)]
423+ [(eqCon, PPi impl (n "a") PSet (
424+ PPi impl (n "x") (PRef bi (n "a"))
425+ (PApp bi (PRef bi eqTy) [pimp (n "a") Placeholder,
426+ pimp (n "b") Placeholder,
427+ pexp (PRef bi (n "x")),
428+ pexp (PRef bi (n "x"))])), bi)]
419429 where n a = MN 0 a
420430
421431-- Defined in builtins.idr
@@ -424,7 +434,7 @@ existsCon = UN ["Exists"]
424434
425435piBind :: [(Name, PTerm)] -> PTerm -> PTerm
426436piBind [] t = t
427−piBind ((n, ty):ns) t = PPi Exp n ty (piBind ns t)
437+piBind ((n, ty):ns) t = PPi expl n ty (piBind ns t)
428438
429439-- Dealing with implicit arguments
430440
@@ -451,18 +461,18 @@ implicitise syn ist tm
451461 = do (decls, ns) <- get
452462 let isn = concatMap (namesIn ist) (map getTm as)
453463 put (decls, nub (ns ++ (isn `dropAll` (env ++ map fst (getImps decls)))))
454− imps top env (PPi Imp n ty sc)
464+ imps top env (PPi (Imp l) n ty sc)
455465 = do let isn = nub (namesIn ist ty) `dropAll` [n]
456466 (decls , ns) <- get
457− put (PImp n ty : decls,
467+ put (PImp l n ty : decls,
458468 nub (ns ++ (isn `dropAll` (env ++ map fst (getImps decls)))))
459469 imps True (n:env) sc
460− imps top env (PPi Exp n ty sc)
470+ imps top env (PPi (Exp l) n ty sc)
461471 = do let isn = nub (namesIn ist ty ++ case sc of
462472 (PRef _ x) -> namesIn ist sc `dropAll` [n]
463473 _ -> [])
464474 (decls, ns) <- get -- ignore decls in HO types
465− put (PExp ty : decls,
475+ put (PExp l ty : decls,
466476 nub (ns ++ (isn `dropAll` (env ++ map fst (getImps decls)))))
467477 imps True (n:env) sc
468478 imps top env (PEq _ l r)
@@ -488,9 +498,10 @@ implicitise syn ist tm
488498 imps top env _ = return ()
489499
490500 pibind using [] sc = sc
491− pibind using (n:ns) sc = case lookup n using of
492− Just ty -> PPi Imp n ty (pibind using ns sc)
493− Nothing -> PPi Imp n Placeholder (pibind using ns sc)
501+ pibind using (n:ns) sc
502+ = case lookup n using of
503+ Just ty -> PPi (Imp False) n ty (pibind using ns sc)
504+ Nothing -> PPi (Imp False) n Placeholder (pibind using ns sc)
494505
495506-- Add implicit arguments in function calls
496507
@@ -541,17 +552,17 @@ addImpl ist ptm = ai [] ptm
541552 appRest fc f (a : as) = appRest fc (PApp fc f [a]) as
542553
543554 insertImpl :: [PArg] -> [PArg] -> [PArg]
544− insertImpl (PExp ty : ps) (PExp tm : given) =
545− PExp tm : insertImpl ps given
546− insertImpl (PImp n ty : ps) given =
555+ insertImpl (PExp l ty : ps) (PExp _ tm : given) =
556+ PExp l tm : insertImpl ps given
557+ insertImpl (PImp l n ty : ps) given =
547558 case find n given [] of
548− Just (tm, given') -> PImp n tm : insertImpl ps given'
549− Nothing -> PImp n Placeholder : insertImpl ps given
559+ Just (tm, given') -> PImp l n tm : insertImpl ps given'
560+ Nothing -> PImp l n Placeholder : insertImpl ps given
550561 insertImpl expected [] = []
551562 insertImpl [] given = given
552563
553564 find n [] acc = Nothing
554− find n (PImp n' t : gs) acc
565+ find n (PImp _ n' t : gs) acc
555566 | n == n' = Just (t, reverse acc ++ gs)
556567 find n (g : gs) acc = find n gs (g : acc)
557568
src/Idris/Compiler.hs+3
@@ -51,6 +51,9 @@ instance ToEpic (TT Name) where
5151 epic' env tm@(App f a)
5252 | (P _ (UN ["mkForeign"]) _, args) <- unApply tm
5353 = doForeign args
54+ | (P _ (UN ["lazy"]) _, [_, arg]) <- unApply tm
55+ = do arg' <- epic' env arg
56+ return $ lazy_ arg'
5457 epic' env (P (DCon t a) n _) = return $ con_ t
5558 epic' env (P (TCon t a) n _) = return $ con_ t
5659 epic' env (P _ n _) = return $ ref (ename n)
src/Idris/Delaborate.hs+6−6
@@ -23,7 +23,7 @@ delab ist tm = de [] tm
2323 | n == falseTy = PFalse un
2424 | otherwise = PRef un n
2525 de env (Bind n (Lam ty) sc) = PLam n (de env ty) (de (n:env) sc)
26− de env (Bind n (Pi ty) sc) = PPi Exp n (de env ty) (de (n:env) sc)
26+ de env (Bind n (Pi ty) sc) = PPi expl n (de env ty) (de (n:env) sc)
2727 de env (Bind n (Let ty val) sc)
2828 = PLet n (de env ty) (de env val) (de (n:env) sc)
2929 de env (Bind n _ sc) = de (n:env) sc
@@ -36,13 +36,13 @@ delab ist tm = de [] tm
3636 deFn env (P _ n _) [_,_,l,r] | n == pairCon = PPair un (de env l) (de env r)
3737 | n == eqTy = PEq un (de env l) (de env r)
3838 deFn env (P _ n _) args = mkPApp n (map (de env) args)
39− deFn env f args = PApp un (de env f) (map PExp (map (de env) args))
39+ deFn env f args = PApp un (de env f) (map pexp (map (de env) args))
4040
4141 mkPApp n args
4242 | Just imps <- lookupCtxt n (idris_implicits ist)
43− = PApp un (PRef un n) (zipWith imp (imps ++ repeat (PExp undefined)) args)
44− | otherwise = PApp un (PRef un n) (map PExp args)
43+ = PApp un (PRef un n) (zipWith imp (imps ++ repeat (pexp undefined)) args)
44+ | otherwise = PApp un (PRef un n) (map pexp args)
4545
46− imp (PImp n _) arg = PImp n arg
47− imp (PExp _) arg = PExp arg
46+ imp (PImp l n _) arg = PImp l n arg
47+ imp (PExp l _) arg = PExp l arg
4848
src/Idris/ElabDecls.hs+32−24
@@ -188,8 +188,8 @@ elabClause info fc (PWith fname lhs withs wval withblock)
188188 mapM_ (elabDecl info) wb
189189
190190 -- rhs becomes: fname' ps wval
191− let rhs = PApp fc (PRef fc wname) (map (PExp . (PRef fc) . fst) bargs ++
192− [PExp wval])
191+ let rhs = PApp fc (PRef fc wname) (map (pexp . (PRef fc) . fst) bargs ++
192+ [pexp wval])
193193 logLvl 3 ("New RHS " ++ show rhs)
194194 ctxt <- getContext -- New context with block added
195195 ((rhs', defer), _) <-
@@ -225,7 +225,7 @@ elabClause info fc (PWith fname lhs withs wval withblock)
225225
226226 updateLHS n wname mvars ns (PApp fc (PRef fc' n') args) w
227227 = return $ substMatches mvars $
228− PApp fc (PRef fc' wname) (map (PExp . (PRef fc')) ns ++ [PExp w])
228+ PApp fc (PRef fc' wname) (map (pexp . (PRef fc')) ns ++ [pexp w])
229229 updateLHS n wname mvars ns tm w = fail $ "Not implemented " ++ show tm
230230
231231pbinds (Bind n (PVar t) sc) = do attack; patbind n
@@ -310,29 +310,29 @@ elab info pattern tm = do elab' tm
310310 elab' (PTrue fc) = try (elab' (PRef fc unitCon))
311311 (elab' (PRef fc unitTy))
312312 elab' (PFalse fc) = elab' (PRef fc falseTy)
313− elab' (PRefl fc) = elab' (PApp fc (PRef fc eqCon) [PImp (MN 0 "a") Placeholder,
314− PImp (MN 0 "x") Placeholder])
315− elab' (PEq fc l r) = elab' (PApp fc (PRef fc eqTy) [PImp (MN 0 "a") Placeholder,
316− PImp (MN 0 "b") Placeholder,
317− PExp l, PExp r])
313+ elab' (PRefl fc) = elab' (PApp fc (PRef fc eqCon) [pimp (MN 0 "a") Placeholder,
314+ pimp (MN 0 "x") Placeholder])
315+ elab' (PEq fc l r) = elab' (PApp fc (PRef fc eqTy) [pimp (MN 0 "a") Placeholder,
316+ pimp (MN 0 "b") Placeholder,
317+ pexp l, pexp r])
318318 elab' (PPair fc l r) = try (elab' (PApp fc (PRef fc pairTy)
319− [PExp l,PExp r]))
319+ [pexp l,pexp r]))
320320 (elab' (PApp fc (PRef fc pairCon)
321− [PImp (MN 0 "A") Placeholder,
322− PImp (MN 0 "B") Placeholder,
323− PExp l, PExp r]))
321+ [pimp (MN 0 "A") Placeholder,
322+ pimp (MN 0 "B") Placeholder,
323+ pexp l, pexp r]))
324324 elab' (PDPair fc l@(PRef _ n) r)
325325 = try (elab' (PApp fc (PRef fc sigmaTy)
326− [PExp Placeholder,
327− PExp (PLam n Placeholder r)]))
326+ [pexp Placeholder,
327+ pexp (PLam n Placeholder r)]))
328328 (elab' (PApp fc (PRef fc existsCon)
329− [PImp (MN 0 "a") Placeholder,
330− PImp (MN 0 "P") Placeholder,
331− PExp l, PExp r]))
329+ [pimp (MN 0 "a") Placeholder,
330+ pimp (MN 0 "P") Placeholder,
331+ pexp l, pexp r]))
332332 elab' (PDPair fc l r) = elab' (PApp fc (PRef fc existsCon)
333− [PImp (MN 0 "a") Placeholder,
334− PImp (MN 0 "P") Placeholder,
335− PExp l, PExp r])
333+ [pimp (MN 0 "a") Placeholder,
334+ pimp (MN 0 "P") Placeholder,
335+ pexp l, pexp r])
336336 elab' (PRef fc n) | pattern && not (inparamBlock n)
337337 = erun fc $
338338 try (do apply (Var n) []; solve)
@@ -372,12 +372,12 @@ elab info pattern tm = do elab' tm
372372 elab' (PApp fc (PRef _ f) args)
373373 | Just ps <- lookupCtxt f (inblock info)
374374 = erun fc $
375− elabApp (liftname info f) (map (PExp . (PRef fc)) ps ++ args)
375+ elabApp (liftname info f) (map (pexp . (PRef fc)) ps ++ args)
376376 | otherwise = erun fc $ elabApp f args
377377 where elabApp f args
378378 = try (do ns <- apply (Var f) (map isph args)
379379 solve
380− elabArgs ns (map getTm args))
380+ elabArgs ns (map (\x -> (lazyarg x, getTm x)) args))
381381 (do apply_elab f (map toElab args)
382382 solve)
383383 elab' (PApp fc f [arg])
@@ -391,8 +391,16 @@ elab info pattern tm = do elab' tm
391391 elab' x = fail $ "Not implemented " ++ show x
392392
393393 elabArgs [] _ = return ()
394− elabArgs (n:ns) (Placeholder : args) = elabArgs ns args
395− elabArgs (n:ns) (t : args) = do focus n; elab' t; elabArgs ns args
394+ elabArgs (n:ns) ((_, Placeholder) : args) = elabArgs ns args
395+ elabArgs (n:ns) ((lazy, t) : args)
396+ | lazy && not pattern
397+ = do focus n; elab' (PApp bi (PRef bi (UN ["lazy"]))
398+ [pimp (UN ["a"]) Placeholder,
399+ pexp t]);
400+ elabArgs ns args
401+ | otherwise
402+ = do focus n; elab' t; elabArgs ns args
403+
396404
397405collectDeferred :: Term -> State [(Name, Type)] Term
398406collectDeferred (Bind n (GHole t) app) =
src/Idris/Parser.hs+71−62
@@ -170,9 +170,17 @@ pSyntaxDecl :: SyntaxInfo -> IParser PDecl
170170pSyntaxDecl syn
171171 = do s <- pSyntaxRule syn
172172 i <- getState
173− setState (i { syntax_rules = s : syntax_rules i })
173+ let rs = syntax_rules i
174+ let ns = syntax_keywords i
175+ let ks = map show (names s)
176+ setState (i { syntax_rules = s : rs,
177+ syntax_keywords = ks ++ ns })
174178 fc <- pfc
175179 return (PSyntax fc s)
180+ where
181+ names (Rule syms _) = mapMaybe ename syms
182+ ename (Keyword n) = Just n
183+ ename _ = Nothing
176184
177185pSyntaxRule :: SyntaxInfo -> IParser Syntax
178186pSyntaxRule syn
@@ -201,8 +209,8 @@ pSynSym = try (do lchar '['; n <- pName; lchar ']'
201209 return (Symbol sym)
202210
203211pFunDecl' :: SyntaxInfo -> IParser PDecl
204−pFunDecl' syn = try (do fc <- pfc
205− n <- pfName; ty <- pTSig syn
212+pFunDecl' syn = try (do n <- pfName; ty <- pTSig syn
213+ fc <- pfc
206214 lchar ';'
207215 ty' <- implicit syn n ty
208216 return (PTy fc n ty'))
@@ -268,8 +276,8 @@ pNoExtExpr syn =
268276 <|> pSimpleExpr syn
269277 <|> try (pLambda syn)
270278 <|> try (pLet syn)
271− <|> try (pPi syn)
272− <|> try (pDoBlock syn)
279+ <|> pPi syn
280+ <|> pDoBlock syn
273281
274282pExtensions :: SyntaxInfo -> [Syntax] -> IParser PTerm
275283pExtensions syn rules = choice (map (\x -> try (pExt syn x)) rules)
@@ -308,12 +316,8 @@ pExt syn (Rule (s:ssym) ptm)
308316 update ns t = t
309317
310318pName = do i <- getState
311− iName (map show (names (syntax_rules i)))
319+ iName (syntax_keywords i)
312320 where
313− names rs = concatMap namesR rs
314− namesR (Rule syms _) = mapMaybe ename syms
315− ename (Keyword n) = Just n
316− ename _ = Nothing
317321
318322pfName = try pName
319323 <|> do lchar '('; o <- operator; lchar ')'; return (UN [o])
@@ -322,21 +326,24 @@ pSimpleExpr syn =
322326 try (do symbol "!["; t <- pTerm; lchar ']'
323327 return $ PQuote t)
324328 <|> try (do lchar '?'; x <- pName; return (PMetavar x))
325− <|> try (do fc <- pfc; reserved "refl"; return (PRefl fc))
326− <|> try (do fc <- pfc; reserved "return"; return (PReturn fc))
327− <|> try (do fc <- pfc; x <- pfName; return (PRef fc x))
328− <|> try (do lchar '('; l <- pExpr syn; lchar ','; fc <- pfc
329− r <- pExpr syn; lchar ')';
330− return (PPair fc l r))
331− <|> try (do lchar '('; l <- pExpr syn; reservedOp "**"; fc <- pfc
332− r <- pExpr syn; lchar ')';
333− return (PDPair fc l r))
329+ <|> try (do reserved "refl"; fc <- pfc; return (PRefl fc))
330+ <|> try (do reserved "return"; fc <- pfc; return (PReturn fc))
331+ <|> try (do x <- pfName; fc <- pfc; return (PRef fc x))
332+ <|> try (pPair syn)
334333 <|> try (do lchar '('; e <- pExpr syn; lchar ')'; return e)
335334 <|> try (do c <- pConstant; return (PConstant c))
336− <|> try (do reserved "Set"; return PSet)
337− <|> try (do fc <- pfc; symbol "()"; return (PTrue fc))
338− <|> try (do fc <- pfc; symbol "_|_"; return (PFalse fc))
339− <|> try (do lchar '_'; return Placeholder)
335+ <|> do reserved "Set"; return PSet
336+ <|> try (do symbol "()"; fc <- pfc; return (PTrue fc))
337+ <|> try (do symbol "_|_"; fc <- pfc; return (PFalse fc))
338+ <|> do lchar '_'; return Placeholder
339+
340+pPair syn = do lchar '('; l <- pExpr syn; op <- pairOp
341+ fc <- pfc
342+ r <- pExpr syn; lchar ')';
343+ return (op fc l r)
344+ where
345+ pairOp = do lchar ','; return PPair
346+ <|> do reservedOp "**"; return PDPair
340347
341348pHSimpleExpr syn
342349 = try (pSimpleExpr syn)
@@ -352,13 +359,13 @@ pApp syn = do f <- pSimpleExpr syn
352359pArg :: SyntaxInfo -> IParser PArg
353360pArg syn = pImplicitArg syn
354361 <|> do e <- pSimpleExpr syn
355− return (PExp e)
362+ return (pexp e)
356363
357364pImplicitArg syn = do lchar '{'; n <- pName
358365 fc <- pfc
359366 v <- option (PRef fc n) (do lchar '='; pExpr syn)
360367 lchar '}'
361− return (PImp n v)
368+ return (pimp n v)
362369
363370pTSig syn = do lchar ':'
364371 pExpr syn
@@ -373,14 +380,16 @@ pLet syn = do reserved "let"; n <- pName; lchar '='; v <- pExpr syn
373380 reserved "in"; sc <- pExpr syn
374381 return (PLet n Placeholder v sc)
375382
376−pPi syn = do lchar '('; xt <- tyDeclList syn; lchar ')'
383+pPi syn = do lazy <- option False (do lchar '|'; return True)
384+ lchar '('; xt <- tyDeclList syn; lchar ')'
377385 symbol "->"
378386 sc <- pExpr syn
379− return (bindList (PPi Exp) xt sc)
380− <|> do lchar '{'; xt <- tyDeclList syn; lchar '}'
387+ return (bindList (PPi (Exp lazy)) xt sc)
388+ <|> do lazy <- option False (do lchar '|'; return True)
389+ lchar '{'; xt <- tyDeclList syn; lchar '}'
381390 symbol "->"
382391 sc <- pExpr syn
383− return (bindList (PPi Imp) xt sc)
392+ return (bindList (PPi (Imp lazy)) xt sc)
384393
385394tyDeclList syn = sepBy1 (do x <- pfName; t <- pTSig syn; return (x,t))
386395 (lchar ',')
@@ -399,14 +408,14 @@ pDoBlock syn
399408 return (PDoBlock ds)
400409
401410pDo syn
402− = try (do fc <- pfc
403− i <- pName; symbol "<-"; e <- pExpr syn;
411+ = try (do i <- pName; symbol "<-"; fc <- pfc
412+ e <- pExpr syn;
404413 return (DoBind fc i e))
405− <|> try (do fc <- pfc
406− reserved "let"; i <- pName; reservedOp "="; e <- pExpr syn
414+ <|> try (do reserved "let"; i <- pName; reservedOp "="; fc <- pfc
415+ e <- pExpr syn
407416 return (DoLet fc i e))
408− <|> try (do fc <- pfc
409− e <- pExpr syn; return (DoExp fc e))
417+ <|> try (do e <- pExpr syn; fc <- pfc
418+ return (DoExp fc e))
410419
411420pConstant :: IParser Const
412421pConstant = do reserved "Int"; return IType
@@ -420,38 +429,38 @@ pConstant = do reserved "Int"; return IType
420429 <|> try (do c <- chlit; return $ Ch c)
421430
422431table fixes
423− = [[prefix "-" (\fc x -> PApp fc (PRef fc (UN ["-"])) [PExp (PConstant (I 0)), PExp x])]]
432+ = [[prefix "-" (\fc x -> PApp fc (PRef fc (UN ["-"])) [pexp (PConstant (I 0)), pexp x])]]
424433 ++ toTable (reverse fixes) ++
425434 [[binary "=" (\fc x y -> PEq fc x y) AssocLeft],
426− [binary "->" (\fc x y -> PPi Exp (MN 0 "X") x y) AssocRight]]
435+ [binary "->" (\fc x y -> PPi expl (MN 0 "X") x y) AssocRight]]
427436
428437toTable fs = map (map toBin)
429438 (groupBy (\ (Fix x _) (Fix y _) -> prec x == prec y) fs)
430439 where toBin (Fix (PrefixN _) op) = prefix op
431− (\fc x -> PApp fc (PRef fc (UN [op])) [PExp x])
440+ (\fc x -> PApp fc (PRef fc (UN [op])) [pexp x])
432441 toBin (Fix f op)
433− = binary op (\fc x y -> PApp fc (PRef fc (UN [op])) [PExp x,PExp y]) (assoc f)
442+ = binary op (\fc x y -> PApp fc (PRef fc (UN [op])) [pexp x,pexp y]) (assoc f)
434443 assoc (Infixl _) = AssocLeft
435444 assoc (Infixr _) = AssocRight
436445 assoc (InfixN _) = AssocNone
437446
438−binary name f assoc = Infix (do { fc <- pfc;
439− reservedOp name; return (f fc) }) assoc
440−prefix name f = Prefix (do { fc <- pfc;
441− reservedOp name; return (f fc) })
447+binary name f assoc = Infix (do { reservedOp name; fc <- pfc;
448+ return (f fc) }) assoc
449+prefix name f = Prefix (do { reservedOp name; fc <- pfc;
450+ return (f fc) })
442451
443452--------- Data declarations ---------
444453
445454pData :: SyntaxInfo -> IParser PDecl
446−pData syn = try (do fc <- pfc
447− reserved "data"; tyn <- pfName; ty <- pTSig syn
455+pData syn = try (do reserved "data"; fc <- pfc
456+ tyn <- pfName; ty <- pTSig syn
448457 reserved "where"
449458 ty' <- implicit syn tyn ty
450459 cons <- sepBy (pConstructor syn) (lchar '|')
451460 lchar ';'
452461 return $ PData fc (PDatadecl tyn ty' cons))
453− <|> do fc <- pfc
454− reserved "data"; tyn <- pfName; args <- many pName
462+ <|> do reserved "data"; fc <- pfc
463+ tyn <- pfName; args <- many pName
455464 lchar '='
456465 cons <- sepBy1 (pSimpleCon syn) (lchar '|')
457466 lchar ';'
@@ -465,31 +474,31 @@ pData syn = try (do fc <- pfc
465474 return $ PData fc (PDatadecl tyn ty' cons')
466475
467476mkPApp fc t [] = t
468−mkPApp fc t xs = PApp fc t (map PExp xs)
477+mkPApp fc t xs = PApp fc t (map pexp xs)
469478
470479bindArgs :: [PTerm] -> PTerm -> PTerm
471480bindArgs [] t = t
472−bindArgs (x:xs) t = PPi Exp (MN 0 "t") x (bindArgs xs t)
481+bindArgs (x:xs) t = PPi expl (MN 0 "t") x (bindArgs xs t)
473482
474483pConstructor :: SyntaxInfo -> IParser (Name, PTerm, FC)
475484pConstructor syn
476− = do fc <- pfc
477− cn <- pfName; ty <- pTSig syn
485+ = do cn <- pfName; fc <- pfc
486+ ty <- pTSig syn
478487 ty' <- implicit syn cn ty
479488 return (cn, ty', fc)
480489
481490pSimpleCon :: SyntaxInfo -> IParser (Name, [PTerm], FC)
482491pSimpleCon syn
483− = do fc <- pfc
484− cn <- pfName
492+ = do cn <- pfName
493+ fc <- pfc
485494 args <- many (pSimpleExpr syn)
486495 return (cn, args, fc)
487496
488497--------- Pattern match clauses ---------
489498
490499pPattern :: SyntaxInfo -> IParser PDecl
491−pPattern syn = do fc <- pfc
492− clause <- pClause syn
500+pPattern syn = do clause <- pClause syn
501+ fc <- pfc
493502 return (PClauses fc (MN 2 "_") [clause]) -- collect together later
494503
495504whereSyn :: Name -> SyntaxInfo -> [PTerm] -> SyntaxInfo
@@ -511,7 +520,7 @@ pClause syn
511520 let wsyn = whereSyn n syn (map getTm iargs ++ args ++ wargs)
512521 wheres <- choice [pWhereblock wsyn, do lchar ';'; return []]
513522 return $ PClause n (PApp fc (PRef fc n)
514− (iargs ++ map PExp args)) wargs rhs wheres)
523+ (iargs ++ map pexp args)) wargs rhs wheres)
515524 <|> try (do n <- pfName
516525 iargs <- many (pImplicitArg syn)
517526 fc <- pfc
@@ -524,7 +533,7 @@ pClause syn
524533 let withs = concat ds
525534 lchar '}'
526535 return $ PWith n (PApp fc (PRef fc n)
527− (iargs ++ map PExp args)) wargs wval withs)
536+ (iargs ++ map pexp args)) wargs wval withs)
528537
529538 <|> do l <- pSimpleExpr syn
530539 op <- operator
@@ -535,7 +544,7 @@ pClause syn
535544 lchar '='
536545 rhs <- pExpr syn
537546 wheres <- choice [pWhereblock syn, do lchar ';'; return []]
538− return $ PClause n (PApp fc (PRef fc n) [PExp l,PExp r]) wargs rhs wheres
547+ return $ PClause n (PApp fc (PRef fc n) [pexp l,pexp r]) wargs rhs wheres
539548
540549 <|> do l <- pSimpleExpr syn
541550 op <- operator
@@ -549,7 +558,7 @@ pClause syn
549558 ds <- many1 $ pFunDecl syn
550559 let withs = concat ds
551560 lchar '}'
552− return $ PWith n (PApp fc (PRef fc n) [PExp l, PExp r]) wargs wval withs
561+ return $ PWith n (PApp fc (PRef fc n) [pexp l, pexp r]) wargs wval withs
553562
554563pWExpr :: SyntaxInfo -> IParser PTerm
555564pWExpr syn = do lchar '|'; pExpr' syn
@@ -587,11 +596,11 @@ expandDo dsl (PDoBlock ds) = expandDo dsl $ block (dsl_bind dsl) ds
587596 block b [DoExp fc tm] = tm
588597 block b [a] = PElabError "Last statement in do block must be an expression"
589598 block b (DoBind fc n tm : rest)
590− = PApp fc (PRef fc b) [PExp tm, PExp (PLam n Placeholder (block b rest))]
599+ = PApp fc (PRef fc b) [pexp tm, pexp (PLam n Placeholder (block b rest))]
591600 block b (DoExp fc tm : rest)
592601 = PApp fc (PRef fc b)
593− [PExp tm,
594− PExp (PLam (MN 0 "bindx") Placeholder (block b rest))]
602+ [pexp tm,
603+ pexp (PLam (MN 0 "bindx") Placeholder (block b rest))]
595604expandDo dsl t = t
596605
597606