on master help sign in
Rename Lazy' => Delayed

There may be reasons for delaying a computation other than it being Lazy (e.g. asynchronous calls may be nice one day). Also, we should avoid terms like 'codata' or 'coinduction' in the library, when in practice it's really about creating infinite structures.

commit536372f4cdcf9f83e0d9bc0d050711206790d111 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateMon 16 May 2016, 13:34 (10 years ago) parenta3b40c2
7 files changed+31−28
libs/prelude/Builtins.idr+16−13 libs/prelude/Prelude/Stream.idr+2−2 src/Idris/Core/Unify.hs+2−2 src/Idris/Coverage.hs+2−2 src/Idris/Elab/Data.hs+2−2 src/Idris/Elab/Term.hs+5−5 src/Idris/TypeSearch.hs+2−2
libs/prelude/Builtins.idr+16−13
@@ -106,38 +106,41 @@ sym Refl = Refl
106106trans : {a:x} -> {b:y} -> {c:z} -> a = b -> b = c -> a = c
107107trans Refl Refl = Refl
108108
109−||| There are two types of laziness: that arising from lazy functions, and that
110−||| arising from codata. They differ in their totality condition.
111−data LazyType = LazyCodata | LazyEval
109+||| Two types of delayed computation: that arising from lazy functions, and that
110+||| arising from infinite data. They differ in their totality condition.
111+data DelayReason = Infinite | LazyValue
112112
113113||| The underlying implementation of Lazy and Inf.
114114%error_reverse
115−data Lazy' : LazyType -> Type -> Type where
115+data Delayed : DelayReason -> Type -> Type where
116116 ||| A delayed computation.
117117 |||
118118 ||| Delay is inserted automatically by the elaborator where necessary.
119119 |||
120120 ||| Note that compiled code gives `Delay` special semantics.
121− ||| @ t whether this is laziness from codata or normal lazy evaluation
121+ ||| @ t whether this is laziness from an infinite structure or lazy evaluation
122122 ||| @ a the type of the eventual value
123123 ||| @ val a computation that will produce a value
124− Delay : {t, a : _} -> (val : a) -> Lazy' t a
124+ Delay : {t, a : _} -> (val : a) -> Delayed t a
125125
126126||| Compute a value from a delayed computation.
127127|||
128128||| Inserted by the elaborator where necessary.
129−Force : {t, a : _} -> Lazy' t a -> a
129+Force : {t, a : _} -> Delayed t a -> a
130130Force (Delay x) = x
131131
132−||| Lazily evaluated values. This has special evaluation semantics.
132+||| Lazily evaluated values.
133+||| At run time, the delayed value will only be computed when required by
134+||| a case split.
133135Lazy : Type -> Type
134−Lazy t = Lazy' LazyEval t
136+Lazy t = Delayed LazyValue t
135137
136−||| Recursive parameters to codata. Inserted automatically by the elaborator
137−||| on a "codata" definition but is necessary by hand if mixing inductive and
138−||| coinductive parameters.
138+||| Possibly infinite data.
139+||| A value which may be infinite is accepted by the totality checker if
140+||| it appears under a data constructor. At run time, the delayed value will
141+||| only be computed when required by a case split.
139142Inf : Type -> Type
140−Inf t = Lazy' LazyCodata t
143+Inf t = Delayed Infinite t
141144
142145namespace Ownership
143146 ||| A read-only version of a unique value
libs/prelude/Prelude/Stream.idr+2−2
@@ -13,8 +13,8 @@ import Prelude.List
1313%default total
1414
1515||| An infinite stream
16−codata Stream : Type -> Type where
17− (::) : (e : a) -> Stream a -> Stream a
16+data Stream : Type -> Type where
17+ (::) : (e : a) -> Inf (Stream a) -> Stream a
1818
1919-- Hints for interactive editing
2020%name Stream xs,ys,zs,ws
src/Idris/Core/Unify.hs+2−2
@@ -712,9 +712,9 @@ envPos x i ((y, _) : ys) | x == y = i
712712-- Issue #1722 on the issue tracker https://github.com/idris-lang/Idris-dev/issues/1722
713713--
714714recoverable t@(App _ _ _) _
715− | (P _ (UN l) _, _) <- unApply t, l == txt "Lazy'" = False
715+ | (P _ (UN l) _, _) <- unApply t, l == txt "Delayed" = False
716716recoverable _ t@(App _ _ _)
717− | (P _ (UN l) _, _) <- unApply t, l == txt "Lazy'" = False
717+ | (P _ (UN l) _, _) <- unApply t, l == txt "Delayed" = False
718718recoverable (P (DCon _ _ _) x _) (P (DCon _ _ _) y _) = x == y
719719recoverable (P (TCon _ _) x _) (P (TCon _ _) y _) = x == y
720720recoverable (TType _) (P (DCon _ _ _) y _) = False
src/Idris/Coverage.hs+2−2
@@ -493,9 +493,9 @@ delazy' all t@(App _ f a)
493493 | (P _ (UN l) _, [_, _, arg]) <- unApply t,
494494 l == txt "Force" = delazy' all arg
495495 | (P _ (UN l) _, [P _ (UN lty) _, _, arg]) <- unApply t,
496− l == txt "Delay" && (all || lty == txt "LazyEval") = delazy arg
496+ l == txt "Delay" && (all || lty /= txt "Infinite") = delazy arg
497497 | (P _ (UN l) _, [P _ (UN lty) _, arg]) <- unApply t,
498− l == txt "Lazy'" && (all || lty == txt "LazyEval") = delazy' all arg
498+ l == txt "Delayed" && (all || lty /= txt "Infinite") = delazy' all arg
499499delazy' all (App s f a) = App s (delazy' all f) (delazy' all a)
500500delazy' all (Bind n b sc) = Bind n (fmap (delazy' all) b) (delazy' all sc)
501501delazy' all t = t
src/Idris/Elab/Data.hs+2−2
@@ -216,8 +216,8 @@ elabCon info syn tn codata expkind dkind (doc, argDocs, n, nfc, t_in, fc, forcen
216216
217217 mkLazy (PPi pl n nfc ty sc)
218218 = let ty' = if getTyName ty
219− then PApp fc (PRef fc [] (sUN "Lazy'"))
220− [pexp (PRef fc [] (sUN "LazyCodata")),
219+ then PApp fc (PRef fc [] (sUN "Delayed"))
220+ [pexp (PRef fc [] (sUN "Infinite")),
221221 pexp ty]
222222 else ty in
223223 PPi pl n nfc ty' (mkLazy sc)
src/Idris/Elab/Term.hs+5−5
@@ -313,13 +313,13 @@ elab ist info emode opts fn tm
313313
314314 forceErr orig env (CantUnify _ (t,_) (t',_) _ _ _)
315315 | (P _ (UN ht) _, _) <- unApply (normalise (tt_ctxt ist) env t),
316− ht == txt "Lazy'" = notDelay orig
316+ ht == txt "Delayed" = notDelay orig
317317 forceErr orig env (CantUnify _ (t,_) (t',_) _ _ _)
318318 | (P _ (UN ht) _, _) <- unApply (normalise (tt_ctxt ist) env t'),
319− ht == txt "Lazy'" = notDelay orig
319+ ht == txt "Delayed" = notDelay orig
320320 forceErr orig env (InfiniteUnify _ t _)
321321 | (P _ (UN ht) _, _) <- unApply (normalise (tt_ctxt ist) env t),
322− ht == txt "Lazy'" = notDelay orig
322+ ht == txt "Delayed" = notDelay orig
323323 forceErr orig env (Elaborating _ _ _ t) = forceErr orig env t
324324 forceErr orig env (ElaboratingArg _ _ _ t) = forceErr orig env t
325325 forceErr orig env (At _ t) = forceErr orig env t
@@ -482,7 +482,7 @@ elab ist info emode opts fn tm
482482 return $ pruneByType env tc (unDelay ty) ist as
483483
484484 unDelay t | (P _ (UN l) _, [_, arg]) <- unApply t,
485− l == txt "Lazy'" = unDelay arg
485+ l == txt "Delayed" = unDelay arg
486486 | otherwise = t
487487
488488 isAmbiguous (CantResolveAlts _) = delayok
@@ -1400,7 +1400,7 @@ elab ist info emode opts fn tm
14001400 let (tyh, _) = unApply (normalise (tt_ctxt ist) env ty)
14011401 let tries = [mkDelay env t, t]
14021402 case tyh of
1403− P _ (UN l) _ | l == txt "Lazy'"
1403+ P _ (UN l) _ | l == txt "Delayed"
14041404 -> return (PAlternative [] FirstSuccess tries)
14051405 _ -> return t
14061406 where
src/Idris/TypeSearch.hs+2−2
@@ -101,10 +101,10 @@ typeFromDef (def, _, _, _, _) = get def where
101101 get (CaseOp _ ty _ _ _ _) = Just ty
102102 get _ = Nothing
103103
104−-- Replace all occurences of `Lazy' s t` with `t` in a type
104+-- Replace all occurences of `Delayed s t` with `t` in a type
105105unLazy :: Type -> Type
106106unLazy typ = case typ of
107− App _ (App _ (P _ lazy _) _) ty | lazy == sUN "Lazy'" -> unLazy ty
107+ App _ (App _ (P _ lazy _) _) ty | lazy == sUN "Delayed" -> unLazy ty
108108 Bind name binder ty -> Bind name (fmap unLazy binder) (unLazy ty)
109109 App s t1 t2 -> App s (unLazy t1) (unLazy t2)
110110 Proj ty i -> Proj (unLazy ty) i