Thread: [pure-lang-svn] SF.net SVN: pure-lang:[638] pure/trunk/lib/prelude.pure
Status: Beta
Brought to you by:
agraef
|
From: <ag...@us...> - 2008-08-27 19:33:05
|
Revision: 638
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=638&view=rev
Author: agraef
Date: 2008-08-27 19:33:15 +0000 (Wed, 27 Aug 2008)
Log Message:
-----------
Fix typo in comment.
Modified Paths:
--------------
pure/trunk/lib/prelude.pure
Modified: pure/trunk/lib/prelude.pure
===================================================================
--- pure/trunk/lib/prelude.pure 2008-08-27 19:31:19 UTC (rev 637)
+++ pure/trunk/lib/prelude.pure 2008-08-27 19:33:15 UTC (rev 638)
@@ -98,8 +98,8 @@
def (f . g) x = f (g x);
/* "Mapsto" operator. This constructor is declared here so that it can be used
- in other standard library modules to denote special kind of pairs which map
- keys to values. Here we only define equality of such pairs. */
+ in other standard library modules to denote special kinds of pairs which
+ map keys to values. Here we only define equality of such pairs. */
(x=>v)==(y=>w) = if x==y then v==w else 0;
(x=>v)!=(y=>w) = if x!=y then 1 else v!=w;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ag...@us...> - 2008-08-29 09:31:33
|
Revision: 656
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=656&view=rev
Author: agraef
Date: 2008-08-29 09:31:43 +0000 (Fri, 29 Aug 2008)
Log Message:
-----------
Add a void-catmap macro rule to optimize the case of list comprehensions with throwaway results.
Modified Paths:
--------------
pure/trunk/lib/prelude.pure
Modified: pure/trunk/lib/prelude.pure
===================================================================
--- pure/trunk/lib/prelude.pure 2008-08-28 15:24:05 UTC (rev 655)
+++ pure/trunk/lib/prelude.pure 2008-08-29 09:31:43 UTC (rev 656)
@@ -97,6 +97,12 @@
def f $ x = f x;
def (f . g) x = f (g x);
+/* The following rule is always valid and optimizes the case of list
+ comprehensions with throwaway results (useful if a list comprehension is
+ evaluated solely for its side effects). */
+
+def void (catmap f x) = do f x;
+
/* "Mapsto" operator. This constructor is declared here so that it can be used
in other standard library modules to denote special kinds of pairs which
map keys to values. Here we only define equality of such pairs. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ag...@us...> - 2008-09-05 09:51:23
|
Revision: 713
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=713&view=rev
Author: agraef
Date: 2008-09-05 09:51:32 +0000 (Fri, 05 Sep 2008)
Log Message:
-----------
Comment change.
Modified Paths:
--------------
pure/trunk/lib/prelude.pure
Modified: pure/trunk/lib/prelude.pure
===================================================================
--- pure/trunk/lib/prelude.pure 2008-09-05 09:38:43 UTC (rev 712)
+++ pure/trunk/lib/prelude.pure 2008-09-05 09:51:32 UTC (rev 713)
@@ -439,7 +439,8 @@
/* Unfortunately, the global list concatenation operator (+) isn't fully
lazy in Pure, because it's also used for arithmetic operations. Using it
here would make foldr (and hence cat) eager. Therefore we use our own
- lazy concatenation operation here. */
+ concatenation operation here, which properly deals with the case that ys
+ is an infinite stream. */
[]+ys = ys;
xs@(_:_)+ys = tick [] xs ys;
tick zs (x:xs) ys = tack (x:zs) ((xs+ys)&) if thunkp xs;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ag...@us...> - 2008-09-05 09:52:20
|
Revision: 714
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=714&view=rev
Author: agraef
Date: 2008-09-05 09:52:31 +0000 (Fri, 05 Sep 2008)
Log Message:
-----------
Comment change.
Modified Paths:
--------------
pure/trunk/lib/prelude.pure
Modified: pure/trunk/lib/prelude.pure
===================================================================
--- pure/trunk/lib/prelude.pure 2008-09-05 09:51:32 UTC (rev 713)
+++ pure/trunk/lib/prelude.pure 2008-09-05 09:52:31 UTC (rev 714)
@@ -440,7 +440,7 @@
lazy in Pure, because it's also used for arithmetic operations. Using it
here would make foldr (and hence cat) eager. Therefore we use our own
concatenation operation here, which properly deals with the case that ys
- is an infinite stream. */
+ is an infinite stream when applied recursively. */
[]+ys = ys;
xs@(_:_)+ys = tick [] xs ys;
tick zs (x:xs) ys = tack (x:zs) ((xs+ys)&) if thunkp xs;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ag...@us...> - 2008-09-05 10:47:23
|
Revision: 715
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=715&view=rev
Author: agraef
Date: 2008-09-05 10:47:34 +0000 (Fri, 05 Sep 2008)
Log Message:
-----------
Improved error handling for refuted lazy matches in scanr and unzip operations.
Modified Paths:
--------------
pure/trunk/lib/prelude.pure
Modified: pure/trunk/lib/prelude.pure
===================================================================
--- pure/trunk/lib/prelude.pure 2008-09-05 09:52:31 UTC (rev 714)
+++ pure/trunk/lib/prelude.pure 2008-09-05 10:47:34 UTC (rev 715)
@@ -377,6 +377,15 @@
scanr f a xs@(_:_) = tick [] xs
with
/* Hack around with thunks to make these matches irrefutable. */
+ tick zs (x:xs) = tack zs us when
+ ys = scanr f a xs&;
+ y = (case ys of
+ y:_ = y;
+ scanr _ _ ys = throw (bad_list_value ys);
+ _ = throw (bad_list_value ys);
+ end)&;
+ us = f x y : ys;
+ end if thunkp xs;
tick zs (x:xs) = tack zs (f x (y when y:_ = ys end)&:ys
when ys = scanr f a xs& end) if thunkp xs;
= tick (x:zs) xs;
@@ -390,8 +399,15 @@
scanr1 f [x] = [x];
scanr1 f xs@(_:_) = tick [] xs
with
- tick zs (x:xs) = tack zs (f x (y when y:_ = ys end)&:ys
- when ys = scanr1 f xs& end) if thunkp xs;
+ tick zs (x:xs) = tack zs us when
+ ys = scanr1 f xs&;
+ y = (case ys of
+ y:_ = y;
+ scanr1 _ ys = throw (bad_list_value ys);
+ _ = throw (bad_list_value ys);
+ end)&;
+ us = f x y : ys;
+ end if thunkp xs;
tick zs xs = case xs of
[x] = tack zs [x];
x:xs = tick (x:zs) xs;
@@ -575,18 +591,24 @@
unzip [] = [],[];
unzip us@(_:_) = foldr accum ([],[]) us
with
- accum u@(x,y) us = x:(xs when xs,_ = us end)&,
- y:(ys when _,ys = us end)& if thunkp us;
- = x:xs,y:ys when xs,ys = us end;
+ accum u@(x,y) us = x:(xs when xs,_ = check us end)&,
+ y:(ys when _,ys = check us end)& if thunkp us;
+ = x:xs,y:ys when xs,ys = check us end;
accum u _ = throw (bad_tuple_value u);
+ check us@(_,_) = us;
+ check (foldr _ _ us) = throw (bad_list_value us);
+ check us = throw (bad_tuple_value us);
end;
unzip3 [] = [],[],[];
unzip3 us@(_:_) = foldr accum ([],[],[]) us
with
- accum u@(x,y,z) us = x:(xs when xs,_,_ = us end)&,
- y:(ys when _,ys,_ = us end)&,
- z:(zs when _,_,zs = us end)& if thunkp us;
- = x:xs,y:ys,z:zs when xs,ys,zs = us end;
+ accum u@(x,y,z) us = x:(xs when xs,_,_ = check us end)&,
+ y:(ys when _,ys,_ = check us end)&,
+ z:(zs when _,_,zs = check us end)& if thunkp us;
+ = x:xs,y:ys,z:zs when xs,ys,zs = check us end;
accum u _ = throw (bad_tuple_value u);
+ check us@(_,_,_) = us;
+ check (foldr _ _ us) = throw (bad_list_value us);
+ check us = throw (bad_tuple_value us);
end;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ag...@us...> - 2008-09-07 06:55:19
|
Revision: 738
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=738&view=rev
Author: agraef
Date: 2008-09-07 06:55:28 +0000 (Sun, 07 Sep 2008)
Log Message:
-----------
Cosmetic changes.
Modified Paths:
--------------
pure/trunk/lib/prelude.pure
Modified: pure/trunk/lib/prelude.pure
===================================================================
--- pure/trunk/lib/prelude.pure 2008-09-07 06:55:01 UTC (rev 737)
+++ pure/trunk/lib/prelude.pure 2008-09-07 06:55:28 UTC (rev 738)
@@ -91,7 +91,7 @@
/* The (normal order) fixed point combinator. */
-fix f = y y when y = \x -> f (x x&) end;
+fix f = y y with y x = f (x x&) end;
/* Some convenient optimization rules which eliminate saturated calls of the
function composition combinators. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ag...@us...> - 2008-09-27 04:41:08
|
Revision: 879
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=879&view=rev
Author: agraef
Date: 2008-09-27 04:41:02 +0000 (Sat, 27 Sep 2008)
Log Message:
-----------
Simplify definition of cat.
Modified Paths:
--------------
pure/trunk/lib/prelude.pure
Modified: pure/trunk/lib/prelude.pure
===================================================================
--- pure/trunk/lib/prelude.pure 2008-09-27 04:15:24 UTC (rev 878)
+++ pure/trunk/lib/prelude.pure 2008-09-27 04:41:02 UTC (rev 879)
@@ -452,16 +452,14 @@
/* Concatenate a list of lists. */
cat [] = [];
-cat xs@(_:_) = foldr (+) [] xs
+cat xs@(_:_) = foldr (tick []) [] xs
with
/* Unfortunately, the global list concatenation operator (+) isn't fully
lazy in Pure, because it's also used for arithmetic operations. Using it
here would make foldr (and hence cat) eager. Therefore we use our own
concatenation operation here, which properly deals with the case that ys
is an infinite stream when applied recursively. */
- []+ys = ys;
- xs@(_:_)+ys = tick [] xs ys;
- tick zs (x:xs) ys = tack (x:zs) ((xs+ys)&) if thunkp xs;
+ tick zs (x:xs) ys = tack (x:zs) (tick [] xs ys&) if thunkp xs;
= tick (x:zs) xs ys;
tick zs [] ys = tack zs ys;
tick zs xs ys = tack zs (xs+ys);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|