[pure-lang-svn] SF.net SVN: pure-lang:[687] pure/trunk
Status: Beta
Brought to you by:
agraef
|
From: <ag...@us...> - 2008-09-03 07:09:02
|
Revision: 687
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=687&view=rev
Author: agraef
Date: 2008-09-03 07:09:12 +0000 (Wed, 03 Sep 2008)
Log Message:
-----------
Overhaul of prelude (non-strict list operations).
Modified Paths:
--------------
pure/trunk/lib/prelude.pure
pure/trunk/lib/strings.pure
pure/trunk/test/prelude.log
Modified: pure/trunk/lib/prelude.pure
===================================================================
--- pure/trunk/lib/prelude.pure 2008-09-03 04:48:36 UTC (rev 686)
+++ pure/trunk/lib/prelude.pure 2008-09-03 07:09:12 UTC (rev 687)
@@ -28,16 +28,12 @@
nullary failed_match; // failed pattern match (lambda, case, etc.)
nullary stack_fault; // not enough stack space (PURE_STACK limit)
-/* Other exceptions defined by the prelude. We use exceptions sparingly, to
- not interfere with symbolic evaluation, but in some cases it makes sense to
- raise special kinds of exceptions in response to obvious error conditions.
- In particular, the 'bad_list_value' exception is raised by functions which
- need to work from the end of a list towards its front. */
+/* Other exceptions defined by the prelude. */
nullary malloc_error; // memory allocation error
nullary out_of_bounds; // tuple or list index is out of bounds (!)
// bad_list_value xs; // not a proper list value (reverse, etc.)
- // xs denotes the offending tail of the list
+// bad_tuple_value xs; // not a proper tuple value (unzip, etc.)
/* Other constants. */
@@ -180,22 +176,39 @@
accum n::int xs = n+#xs;
end;
-(x,xs)!n::int = throw out_of_bounds if n<0;
+[]!n::int = throw out_of_bounds;
(x:xs)!0 = x;
-(x:xs)!n::int = xs!(n-1);
-[]!n::int = throw out_of_bounds;
+(x:xs)!n::int = xs!(n-1) if n>0;
+ = throw out_of_bounds otherwise;
+/* List concatenation. For a robust implementation which works with both
+ ordinary lists and streams, we want this to be tail-recursive *and*
+ non-strict. So we first walk down the list, popping elements from the first
+ operand until we find an empty or thunked tail ('tick'), then walk back up
+ again, pushing elements in front of the result list ('tack'). */
+
[]+ys = ys;
-(x:xs)+ys = x : accum ys (reverse xs) with
- accum ys (x:xs) = accum (x:ys) xs;
- accum ys [] = ys;
+xs@(_:_)+ys = tick [] xs ys
+with
+ tick zs (x:xs) ys = tack (x:zs) ((xs+ys)&) if thunkp xs;
+ = tick (x:zs) xs ys;
+ tick zs [] ys = tack zs ys;
+ /* Handle an improper list tail (xs+ys is in normal form here). */
+ tick zs xs ys = tack zs (xs+ys);
+ tack (x:xs) ys = tack xs (x:ys);
+ tack [] ys = ys;
end;
+/* List reversal. This is a strict operation, of course, so it will loop on
+ infinite lists. Also, this is one of the few list operations which throws
+ an exception for improper lists, since in that case there really isn't any
+ meaningful value to return. */
+
reverse [] = [];
reverse (x:xs) = accum [x] xs with
accum ys (x:xs) = accum (x:ys) xs;
accum ys [] = ys;
- accum _ xs = throw (bad_list_value xs);
+ accum ys xs = throw (bad_list_value xs);
end;
/* Convert between lists and tuples. */
@@ -213,12 +226,23 @@
accum ys xs = ys,xs;
end;
+/* Convert between lists and streams. */
+
+list [] = [];
+list (x:xs) = x:list xs;
+
+stream [] = [];
+stream (x:xs) = x:xs if thunkp xs;
+ = x:stream xs& otherwise;
+
/* Slicing. xs!!ns returns the list of xs!n for all members n of the index
- list ns which are in the range 0..#xs-1. xs must be a (proper) list or
- tuple, and the indices must be machine ints. */
+ list ns which are in the valid index range. This is a generic definition
+ which will work with any kind of container data structure which defines (!)
+ in such a manner that it throws an exception when the index is out of
+ bounds. */
-xs!!ns = [xs!n; n=ns; n>=0 && n<m] when m::int = #xs end
- if listp xs || tuplep xs;
+xs!!ns = catmap (nth xs) ns
+ with nth xs n = catch (cst []) [xs!n] end;
/* Arithmetic sequences. */
@@ -231,139 +255,205 @@
/* Common list functions. This mostly comes straight from the Q prelude which
in turn was based on the first edition of the Bird/Wadler book, and is very
similar to what you can find in the Haskell prelude. Some functions have
- slightly different names, though, and some of the definitions were massaged
- to make them tail-recursive. */
+ slightly different names, though, and of course everything is typed
+ dynamically. Some of the definitions aren't exactly pretty, but they are
+ like that because we want them to be both efficient and robust. In
+ particular, we require that they do all the necessary argument checking,
+ are tail-recursive and handle lazy lists as gracefully as possible. */
-all p [] = 1;
-all p (x:xs) = if p x then all p xs else 0;
+all p [] = 1;
+all p (x:xs) = if p x then all p xs else 0;
-any p [] = 0;
-any p (x:xs) = if p x then 1 else any p xs;
+any p [] = 0;
+any p (x:xs) = if p x then 1 else any p xs;
-do f [] = ();
-do f (x:xs) = f x $$ do f xs;
+do f [] = ();
+do f (x:xs) = f x $$ do f xs;
-drop n::int [] = [];
-drop n::int (x:xs)
- = drop (n-1) xs if n>0;
- = x:xs otherwise;
+drop n::int [] = [];
+drop n::int ys@(x:xs) = drop (n-1) xs if n>1;
+ = xs if n==1;
+ = ys otherwise;
-dropwhile p [] = [];
-dropwhile p (x:xs)
- = dropwhile p xs if p x;
- = x:xs otherwise;
+dropwhile p [] = [];
+dropwhile p ys@(x:xs) = dropwhile p xs if p x;
+ = ys otherwise;
-filter p [] = [];
-filter p (x:xs) = accum [] (x:xs) with
- accum ys [] = reverse ys;
- accum ys (x:xs) = accum (x:ys) xs if p x;
- = accum ys xs otherwise;
- accum ys xs = reverse ys+filter p xs;
- end;
+filter p [] = [];
+filter p xs@(_:_) = tick [] xs
+with
+ add p x xs = if p x then x:xs else xs;
+ tick zs (x:xs) = tack (add p x zs) (filter p xs&) if thunkp xs;
+ = tick (add p x zs) xs;
+ tick zs [] = tack zs [];
+ tick _ xs = throw (bad_list_value xs);
+ tack (x:xs) ys = tack xs (x:ys);
+ tack [] ys = ys;
+end;
-foldl f a [] = a;
-foldl f a (x:xs)
- = foldl f (f a x) xs;
+foldl f a [] = a;
+foldl f a (x:xs) = foldl f (f a x) xs;
-foldl1 f (x:xs) = foldl f x xs;
+foldl1 f (x:xs) = foldl f x xs;
-foldr f a [] = a;
-foldr f a (x:xs)
- = f x (foldl (flip f) a (reverse xs));
+foldr f a [] = a;
+foldr f a xs@(_:_) = tick [] xs
+with
+ tick zs (x:xs) = tack (x:zs) (foldr f a xs&) if thunkp xs;
+ = tick (x:zs) xs;
+ tick zs [] = tack zs a;
+ tick zs xs = tack zs (foldr f a xs);
+ tack (x:xs) y = tack xs (f x y);
+ tack [] y = y;
+end;
-foldr1 f [x] = x;
-foldr1 f (x:xs) = f x (foldl1 (flip f) (reverse xs));
+foldr1 f [x] = x;
+foldr1 f xs@(_:_) = tick [] xs
+with
+ /* Do the thunkp check first, before probing the tail. Note that the first
+ foldr1 rule above ensures that the topmost tail is already evaluated, so
+ that we always make some progress here. */
+ tick zs ys@(_:xs) = tack zs (foldr1 f ys&) if thunkp xs;
+ tick zs xs = case xs of
+ [x] = tack zs x;
+ x:xs = tick (x:zs) xs;
+ _ = tack zs (foldr1 f xs);
+ end;
+ tack (x:xs) y = tack xs (f x y);
+ tack [] y = y;
+end;
-head (x:xs) = x;
+head (x:xs) = x;
-init [x] = [];
-init (x:xs) = accum [x] xs with
- accum ys [x] = reverse ys;
- accum ys (x:xs) = accum (x:ys) xs;
- accum ys xs = reverse ys+init xs;
- end;
+init [x] = [];
+init xs@(_:_) = tick [] xs
+with
+ tick zs ys@(_:xs) = tack zs (init ys&) if thunkp xs;
+ tick zs xs = case xs of
+ [x] = tack zs [];
+ x:xs = tick (x:zs) xs;
+ _ = tack zs (init xs);
+ end;
+ tack (x:xs) ys = tack xs (x:ys);
+ tack [] ys = ys;
+end;
-last [x] = x;
-last (x:xs) = last xs;
+last [x] = x;
+last (x:xs) = last xs;
-map f [] = [];
-map f (x:xs) = accum [f x] xs with
- accum ys [] = reverse ys;
- accum ys (x:xs) = accum (f x:ys) xs;
- accum ys xs = reverse ys+map f xs;
- end;
+map f [] = [];
+map f xs@(_:_) = tick [] xs
+with
+ tick zs (x:xs) = tack (f x:zs) (map f xs&) if thunkp xs;
+ = tick (f x:zs) xs;
+ tick zs [] = tack zs [];
+ tick zs xs = tack zs (map f xs);
+ tack (x:xs) ys = tack xs (x:ys);
+ tack [] ys = ys;
+end;
-scanl f a [] = [a];
-scanl f a (x:xs)
- = accum [a] (f a x) xs with
- accum ys a [] = reverse (a:ys);
- accum ys a (x:xs) = accum (a:ys) (f a x) xs;
- accum _ _ xs = throw (bad_list_value xs);
- end;
+scanl f a [] = [a];
+scanl f a xs@(_:_) = tick a [] xs
+with
+ tick a zs (x:xs) = tack (a:zs) (scanl f (f a x) xs&) if thunkp xs;
+ = tick (f a x) (a:zs) xs;
+ tick a zs [] = tack zs [a];
+ tick a zs xs = tack zs (scanl f a xs);
+ tack (x:xs) ys = tack xs (x:ys);
+ tack [] ys = ys;
+end;
-scanl1 f [] = [];
-scanl1 f (x:xs) = accum [] x xs with
- accum ys a [] = reverse (a:ys);
- accum ys a (x:xs) = accum (a:ys) (f a x) xs;
- accum _ _ xs = throw (bad_list_value xs);
- end;
+scanl1 f [] = [];
+scanl1 f (x:xs) = scanl f x xs;
-scanr f a [] = [a];
-scanr f a (x:xs)
- = f x y:ys when
- ys = reverse (scanl (flip f) a (reverse xs));
- y:_ = ys;
- end;
+scanr f a [] = [a];
+scanr f a xs@(_:_) = tick [] xs
+with
+ /* Hack around with thunks to make these matches irrefutable. */
+ 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;
+ tick zs [] = tack zs [a];
+ tick zs xs = throw (bad_list_value xs);
+ tack (x:xs) ys = tack xs (f x y:ys) when y:_ = ys end;
+ tack [] ys = ys;
+end;
-scanr1 f [] = [];
-scanr1 f [x] = [x];
-scanr1 f (x:xs) = f x y:ys when
- ys = reverse (scanl1 (flip f) (reverse xs));
- y:_ = ys;
- end;
+scanr1 f [] = [];
+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 xs = case xs of
+ [x] = tack zs [x];
+ x:xs = tick (x:zs) xs;
+ _ = throw (bad_list_value xs);
+ end;
+ tack (x:xs) ys = tack xs (f x y:ys) when y:_ = ys end;
+ tack [] ys = ys;
+end;
-tail (x:xs) = xs;
+tail (x:xs) = xs;
-take n::int [] = [];
-take n::int (x:xs)
- = accum n [] (x:xs) with
- accum _ ys [] = reverse ys;
- accum n::int ys _ = reverse ys if n<=0;
- accum n::int ys (x:xs)
- = accum (n-1) (x:ys) xs;
- accum n ys xs = reverse ys+take n xs;
- end;
+take n::int [] = [];
+take n::int xs@(_:_) = tick n [] xs
+with
+ tick n::int zs xs = tack zs [] if n<=0;
+ = case xs of
+ [] = tack zs [];
+ x:xs = tick (n-1) (x:zs) xs;
+ _ = tack zs (take n xs);
+ end;
+ tack (x:xs) ys = tack xs (x:ys);
+ tack [] ys = ys;
+end;
takewhile p [] = [];
-takewhile p (x:xs)
- = accum [] (x:xs) with
- accum ys [] = reverse ys;
- accum ys (x:xs) = accum (x:ys) xs if p x;
- = reverse ys otherwise;
- accum ys xs = reverse ys+takewhile p xs;
- end;
+takewhile p xs@(_:_) = tick [] xs
+with
+ tick zs [] = tack zs [];
+ tick zs (x:xs) = tick (x:zs) xs if p x;
+ = tack zs [];
+ tick zs xs = tack zs (takewhile p xs);
+ tack (x:xs) ys = tack xs (x:ys);
+ tack [] ys = ys;
+end;
/* Concatenate a list of lists. */
-cat [] = [];
-cat [xs] = xs;
-cat (xs:xss) = accum (reverse xs) xss with
- accum xs [] = reverse xs;
- accum xs ([]:yss) = accum xs yss;
- accum xs ((y:ys):yss) = accum (y:xs) (ys:yss);
- accum _ (ys:_) = throw (bad_list_value ys);
- accum _ yss = throw (bad_list_value yss);
+cat [] = [];
+cat xs@(_:_) = foldr (+) [] 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
+ lazy concatenation operation here. */
+ []+ys = ys;
+ xs@(_:_)+ys = tick [] xs ys;
+ tick zs (x:xs) ys = tack (x:zs) ((xs+ys)&) if thunkp xs;
+ = tick (x:zs) xs ys;
+ tick zs [] ys = tack zs ys;
+ tick zs xs ys = tack zs (xs+ys);
+ tack (x:xs) ys = tack xs (x:ys);
+ tack [] ys = ys;
end;
-/* Combine cat and map. This is used by list comprehensions. */
+/* Map a function to a list and concatenate the results. This is used by list
+ comprehensions. */
-catmap f xs = cat (map f xs);
+catmap f [] = [];
+catmap f xs@(_:_) = cat (map f xs);
+/* NOTE: This definition (from the Haskell prelude) is better, but doesn't
+ preserve left-to-right execution order. */
+//catmap f xs@(_:_) = foldr ((+).f) [] xs;
+
/* Search an element in a list. Returns -1 if not found, index of first
occurrence otherwise. */
-index [] _ = -1;
-index (x:xs) y = search 0 (x:xs) with
+index [] _ = -1;
+index (x:xs) y = search 0 (x:xs) with
search _ [] = -1;
search n::int (x:xs) = n if x==y;
= search (n+1) xs;
@@ -372,49 +462,93 @@
/* Some useful list generators. */
-repeat n::int x = accum [] n x with
+repeat n::int x = accum [] n x with
accum xs n::int x = xs if n<=0;
= accum (x:xs) (n-1) x;
end;
-cycle n::int [] = [];
-cycle n::int (x:xs)
- = [] if n<=0;
- = accum [] n with
- accum ys n::int = cat ys+take n xs if n<=m;
- = accum (xs:ys) (n-m) otherwise;
- end when xs = x:xs; m::int = #xs end if listp xs;
+cycle n::int [] = [];
+cycle n::int (x:xs) = [] if n<=0;
+ = accum [] n with
+ accum ys n::int = cat ys+take n xs if n<=m;
+ = accum (xs:ys) (n-m) otherwise;
+ end when xs = x:xs; m::int = #xs end if listp xs;
-while p f a = accum [] p f a with
- accum as p f a = accum (a:as) p f (f a) if p a;
- = reverse as otherwise;
- end;
+while p f a = accum [] p f a with
+ accum as p f a = accum (a:as) p f (f a) if p a;
+ = reverse as otherwise;
+ end;
-until p f a = accum [] p f a with
- accum as p f a = reverse as if p a;
- = accum (a:as) p f (f a) otherwise;
- end;
+until p f a = accum [] p f a with
+ accum as p f a = reverse as if p a;
+ = accum (a:as) p f (f a) otherwise;
+ end;
/* zip, unzip and friends. */
-zip xs ys = accum [] xs ys with
- accum us (x:xs) (y:ys) = accum ((x,y):us) xs ys;
- accum us _ _ = reverse us;
+zip [] _ |
+zip _ [] = [];
+zip xs@(_:_) ys@(_:_) = tick [] xs ys
+with
+ tick us (x:xs) (y:ys) = tack ((x,y):us) (zip xs ys&)
+ if thunkp xs || thunkp ys;
+ = tick ((x,y):us) xs ys;
+ tick us [] _ |
+ tick us _ [] = tack us [];
+ tick us xs ys = tack us (zip xs ys);
+ tack (u:us) vs = tack us (u:vs);
+ tack [] vs = vs;
end;
-zip3 xs ys zs = accum [] xs ys zs with
- accum us (x:xs) (y:ys) (z:zs) = accum ((x,y,z):us) xs ys zs;
- accum us _ _ _ = reverse us;
+zip3 [] _ _ |
+zip3 _ [] _ |
+zip3 _ _ [] = [];
+zip3 xs@(_:_) ys@(_:_) zs@(_:_)
+ = tick [] xs ys zs
+with
+ tick us (x:xs) (y:ys) (z:zs)
+ = tack ((x,y,z):us) (zip3 xs ys zs&)
+ if thunkp xs || thunkp ys || thunkp zs;
+ = tick ((x,y,z):us) xs ys zs;
+ tick us [] _ _ |
+ tick us _ [] _ |
+ tick us _ _ [] = tack us [];
+ tick us xs ys zs = tack us (zip3 xs ys zs);
+ tack (u:us) vs = tack us (u:vs);
+ tack [] vs = vs;
end;
-zipwith f xs ys = accum [] xs ys with
- accum us (x:xs) (y:ys) = accum (f x y:us) xs ys;
- accum us _ _ = reverse us;
+zipwith f [] _ |
+zipwith f _ [] = [];
+zipwith f xs@(_:_) ys@(_:_)
+ = tick [] xs ys
+with
+ tick us (x:xs) (y:ys) = tack (f x y:us) (zipwith f xs ys&)
+ if thunkp xs || thunkp ys;
+ = tick (f x y:us) xs ys;
+ tick us [] _ |
+ tick us _ [] = tack us [];
+ tick us xs ys = tack us (zipwith f xs ys);
+ tack (u:us) vs = tack us (u:vs);
+ tack [] vs = vs;
end;
-zipwith3 f xs ys zs = accum [] xs ys zs with
- accum us (x:xs) (y:ys) (z:zs) = accum (f x y z:us) xs ys zs;
- accum us _ _ _ = reverse us;
+zipwith3 f [] _ _ |
+zipwith3 f _ [] _ |
+zipwith3 f _ _ [] = [];
+zipwith3 f xs@(_:_) ys@(_:_) zs@(_:_)
+ = tick [] xs ys zs
+with
+ tick us (x:xs) (y:ys) (z:zs)
+ = tack (f x y z:us) (zipwith3 f xs ys zs&)
+ if thunkp xs || thunkp ys || thunkp zs;
+ = tick (f x y z:us) xs ys zs;
+ tick us [] _ _ |
+ tick us _ [] _ |
+ tick us _ _ [] = tack us [];
+ tick us xs ys zs = tack us (zipwith3 f xs ys zs);
+ tack (u:us) vs = tack us (u:vs);
+ tack [] vs = vs;
end;
dowith f (x:xs) (y:ys) = f x y $$ dowith f xs ys;
@@ -425,17 +559,20 @@
dowith3 f _ _ _ = () otherwise;
unzip [] = [],[];
-unzip ((x,y):us) = x:xs,y:ys when xs,ys = accum [] [] us end
+unzip us@(_:_) = foldr accum ([],[]) us
with
- accum xs ys [] = reverse xs,reverse ys;
- accum xs ys ((x,y):us) = accum (x:xs) (y:ys) us;
- accum _ _ us = throw (bad_list_value us);
+ 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 _ = throw (bad_tuple_value u);
end;
unzip3 [] = [],[],[];
-unzip3 ((x,y,z):us) = x:xs,y:ys,z:zs when xs,ys,zs = accum [] [] [] us end
+unzip3 us@(_:_) = foldr accum ([],[],[]) us
with
- accum xs ys zs [] = reverse xs,reverse ys,reverse zs;
- accum xs ys zs ((x,y,z):us) = accum (x:xs) (y:ys) (z:zs) us;
- accum _ _ _ us = throw (bad_list_value us);
+ 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 _ = throw (bad_tuple_value u);
end;
Modified: pure/trunk/lib/strings.pure
===================================================================
--- pure/trunk/lib/strings.pure 2008-09-03 04:48:36 UTC (rev 686)
+++ pure/trunk/lib/strings.pure 2008-09-03 07:09:12 UTC (rev 687)
@@ -151,19 +151,22 @@
end;
end when m = #delim end if not null delim;
-/* Slicing. */
+/* Conversions between between strings and lists, streams and tuples. */
-s::string!!ns = strcat [s!n; n=ns; n>=0 && n<m]
- when m::int = #s end;
+list s::string = chars s;
+stream s::string = stream (chars s);
+tuple s::string = tuple (chars s);
/* Define the customary list operations on strings, so that these can mostly
be used as if they were lists. */
-list s::string = chars s;
-tuple s::string = tuple (chars s);
+s::string+[] = chars s;
+s::string+xs@(_:_) = chars s+xs;
+[]+s::string+[] = chars s;
+xs@(_:_)+s::string = xs+chars s;
reverse s::string = strcat (reverse (chars s));
-cat (s::string:xs) = cat (chars s:xs);
+catmap f s::string = catmap f (chars s);
cycle n::int "" = "";
cycle n::int s::string = "" if n<=0;
Modified: pure/trunk/test/prelude.log
===================================================================
--- pure/trunk/test/prelude.log 2008-09-03 04:48:36 UTC (rev 686)
+++ pure/trunk/test/prelude.log 2008-09-03 07:09:12 UTC (rev 687)
@@ -134,35 +134,79 @@
state 12: #0 #2
state 13: #1 #2
} end;
-(x/*0:0101*/,xs/*0:011*/)!n/*0:1*/::int = throw out_of_bounds if n/*0:1*/<0;
+[]!n/*0:1*/::int = throw out_of_bounds;
(x/*0:0101*/:xs/*0:011*/)!0 = x/*0:0101*/;
-(x/*0:0101*/:xs/*0:011*/)!n/*0:1*/::int = xs/*0:011*/!(n/*0:1*/-1);
-[]!n/*0:1*/::int = throw out_of_bounds;
+(x/*0:0101*/:xs/*0:011*/)!n/*0:1*/::int = xs/*0:011*/!(n/*0:1*/-1) if n/*0:1*/>0;
+(x/*0:0101*/:xs/*0:011*/)!n/*0:1*/::int = throw out_of_bounds;
[]+ys/*0:1*/ = ys/*0:1*/;
-(x/*0:0101*/:xs/*0:011*/)+ys/*0:1*/ = x/*0:0101*/:accum/*0*/ ys/*0:1*/ (reverse xs/*0:011*/) with accum ys/*0:01*/ (x/*0:101*/:xs/*0:11*/) = accum/*1*/ (x/*0:101*/:ys/*0:01*/) xs/*0:11*/; accum ys/*0:01*/ [] = ys/*0:01*/ {
- rule #0: accum ys (x:xs) = accum (x:ys) xs
- rule #1: accum ys [] = ys
+xs@(_/*0:0101*/:_/*0:011*/)+ys/*0:1*/ = tick/*0*/ [] xs/*0:01*/ ys/*0:1*/ with tick zs/*0:001*/ (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tack/*1*/ (x/*0:0101*/:zs/*0:001*/) ((xs/*1:011*/+ys/*1:1*/)&) if thunkp xs/*0:011*/; tick zs/*0:001*/ (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tick/*1*/ (x/*0:0101*/:zs/*0:001*/) xs/*0:011*/ ys/*0:1*/; tick zs/*0:001*/ [] ys/*0:1*/ = tack/*1*/ zs/*0:001*/ ys/*0:1*/; tick zs/*0:001*/ xs/*0:01*/ ys/*0:1*/ = tack/*1*/ zs/*0:001*/ (xs/*0:01*/+ys/*0:1*/) {
+ rule #0: tick zs (x:xs) ys = tack (x:zs) ((xs+ys)&) if thunkp xs
+ rule #1: tick zs (x:xs) ys = tick (x:zs) xs ys
+ rule #2: tick zs [] ys = tack zs ys
+ rule #3: tick zs xs ys = tack zs (xs+ys)
+ state 0: #0 #1 #2 #3
+ <var> state 1
+ state 1: #0 #1 #2 #3
+ <var> state 2
+ <app> state 4
+ [] state 17
+ state 2: #3
+ <var> state 3
+ state 3: #3
+ state 4: #0 #1 #3
+ <var> state 5
+ <app> state 8
+ state 5: #3
+ <var> state 6
+ state 6: #3
+ <var> state 7
+ state 7: #3
+ state 8: #0 #1 #3
+ <var> state 9
+ : state 13
+ state 9: #3
+ <var> state 10
+ state 10: #3
+ <var> state 11
+ state 11: #3
+ <var> state 12
+ state 12: #3
+ state 13: #0 #1 #3
+ <var> state 14
+ state 14: #0 #1 #3
+ <var> state 15
+ state 15: #0 #1 #3
+ <var> state 16
+ state 16: #0 #1 #3
+ state 17: #2 #3
+ <var> state 18
+ state 18: #2 #3
+}; tack (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tack/*1*/ xs/*0:011*/ (x/*0:0101*/:ys/*0:1*/); tack [] ys/*0:1*/ = ys/*0:1*/ {
+ rule #0: tack (x:xs) ys = tack xs (x:ys)
+ rule #1: tack [] ys = ys
state 0: #0 #1
- <var> state 1
- state 1: #0 #1
+ <app> state 1
+ [] state 7
+ state 1: #0
<app> state 2
- [] state 7
state 2: #0
- <app> state 3
+ : state 3
state 3: #0
- : state 4
+ <var> state 4
state 4: #0
<var> state 5
state 5: #0
<var> state 6
state 6: #0
state 7: #1
+ <var> state 8
+ state 8: #1
} end;
reverse [] = [];
-reverse (x/*0:101*/:xs/*0:11*/) = accum/*0*/ [x/*0:101*/] xs/*0:11*/ with accum ys/*0:01*/ (x/*0:101*/:xs/*0:11*/) = accum/*1*/ (x/*0:101*/:ys/*0:01*/) xs/*0:11*/; accum ys/*0:01*/ [] = ys/*0:01*/; accum _/*0:01*/ xs/*0:1*/ = throw (bad_list_value xs/*0:1*/) {
+reverse (x/*0:101*/:xs/*0:11*/) = accum/*0*/ [x/*0:101*/] xs/*0:11*/ with accum ys/*0:01*/ (x/*0:101*/:xs/*0:11*/) = accum/*1*/ (x/*0:101*/:ys/*0:01*/) xs/*0:11*/; accum ys/*0:01*/ [] = ys/*0:01*/; accum ys/*0:01*/ xs/*0:1*/ = throw (bad_list_value xs/*0:1*/) {
rule #0: accum ys (x:xs) = accum (x:ys) xs
rule #1: accum ys [] = ys
- rule #2: accum _ xs = throw (bad_list_value xs)
+ rule #2: accum ys xs = throw (bad_list_value xs)
state 0: #0 #1 #2
<var> state 1
state 1: #0 #1 #2
@@ -254,17 +298,19 @@
state 12: #0 #2
state 13: #1 #2
} end;
-xs/*0:01*/!!ns/*0:1*/ = catmap (\n/*0:*/ -> if n/*0:*/>=0&&n/*0:*/<m/*1:*/ then [xs/*2:01*/!n/*0:*/] else [] {
- rule #0: n = if n>=0&&n<m then [xs!n] else []
+list [] = [];
+list (x/*0:101*/:xs/*0:11*/) = x/*0:101*/:list xs/*0:11*/;
+stream [] = [];
+stream (x/*0:101*/:xs/*0:11*/) = x/*0:101*/:xs/*0:11*/ if thunkp xs/*0:11*/;
+stream (x/*0:101*/:xs/*0:11*/) = x/*0:101*/:stream xs/*1:11*/&;
+xs/*0:01*/!!ns/*0:1*/ = catmap (nth/*0*/ xs/*0:01*/) ns/*0:1*/ with nth xs/*0:01*/ n/*0:1*/ = catch (cst []) [xs/*1:01*/!n/*1:1*/] {
+ rule #0: nth xs n = catch (cst []) [xs!n]
state 0: #0
<var> state 1
state 1: #0
-}) ns/*1:1*/ when m/*0:*/::int = #xs/*0:01*/ {
- rule #0: m::int = #xs
- state 0: #0
- <var>::int state 1
- state 1: #0
-} end if listp xs/*0:01*/||tuplep xs/*0:01*/;
+ <var> state 2
+ state 2: #0
+} end;
n1/*0:0101*/,n2/*0:011*/..m/*0:1*/ = while (\i/*0:*/ -> s/*1:*/*i/*0:*/<=s/*1:*/*m/*3:1*/ {
rule #0: i = s*i<=s*m
state 0: #0
@@ -304,193 +350,407 @@
do f/*0:01*/ [] = ();
do f/*0:01*/ (x/*0:101*/:xs/*0:11*/) = f/*0:01*/ x/*0:101*/$$do f/*0:01*/ xs/*0:11*/;
drop n/*0:01*/::int [] = [];
-drop n/*0:01*/::int (x/*0:101*/:xs/*0:11*/) = drop (n/*0:01*/-1) xs/*0:11*/ if n/*0:01*/>0;
-drop n/*0:01*/::int (x/*0:101*/:xs/*0:11*/) = x/*0:101*/:xs/*0:11*/;
+drop n/*0:01*/::int ys@(x/*0:101*/:xs/*0:11*/) = drop (n/*0:01*/-1) xs/*0:11*/ if n/*0:01*/>1;
+drop n/*0:01*/::int ys@(x/*0:101*/:xs/*0:11*/) = xs/*0:11*/ if n/*0:01*/==1;
+drop n/*0:01*/::int ys@(x/*0:101*/:xs/*0:11*/) = ys/*0:1*/;
dropwhile p/*0:01*/ [] = [];
-dropwhile p/*0:01*/ (x/*0:101*/:xs/*0:11*/) = dropwhile p/*0:01*/ xs/*0:11*/ if p/*0:01*/ x/*0:101*/;
-dropwhile p/*0:01*/ (x/*0:101*/:xs/*0:11*/) = x/*0:101*/:xs/*0:11*/;
+dropwhile p/*0:01*/ ys@(x/*0:101*/:xs/*0:11*/) = dropwhile p/*0:01*/ xs/*0:11*/ if p/*0:01*/ x/*0:101*/;
+dropwhile p/*0:01*/ ys@(x/*0:101*/:xs/*0:11*/) = ys/*0:1*/;
filter p/*0:01*/ [] = [];
-filter p/*0:01*/ (x/*0:101*/:xs/*0:11*/) = accum/*0*/ [] (x/*0:101*/:xs/*0:11*/) with accum ys/*0:01*/ [] = reverse ys/*0:01*/; accum ys/*0:01*/ (x/*0:101*/:xs/*0:11*/) = accum/*1*/ (x/*0:101*/:ys/*0:01*/) xs/*0:11*/ if p/*1:01*/ x/*0:101*/; accum ys/*0:01*/ (x/*0:101*/:xs/*0:11*/) = accum/*1*/ ys/*0:01*/ xs/*0:11*/; accum ys/*0:01*/ xs/*0:1*/ = reverse ys/*0:01*/+filter p/*1:01*/ xs/*0:1*/ {
- rule #0: accum ys [] = reverse ys
- rule #1: accum ys (x:xs) = accum (x:ys) xs if p x
- rule #2: accum ys (x:xs) = accum ys xs
- rule #3: accum ys xs = reverse ys+filter p xs
+filter p/*0:01*/ xs@(_/*0:101*/:_/*0:11*/) = tick/*0*/ [] xs/*0:1*/ with tick zs/*0:01*/ (x/*0:101*/:xs/*0:11*/) = tack/*1*/ (add/*1*/ p/*1:01*/ x/*0:101*/ zs/*0:01*/) (filter p/*2:01*/ xs/*1:11*/&) if thunkp xs/*0:11*/; tick zs/*0:01*/ (x/*0:101*/:xs/*0:11*/) = tick/*1*/ (add/*1*/ p/*1:01*/ x/*0:101*/ zs/*0:01*/) xs/*0:11*/; tick zs/*0:01*/ [] = tack/*1*/ zs/*0:01*/ []; tick _/*0:01*/ xs/*0:1*/ = throw (bad_list_value xs/*0:1*/) {
+ rule #0: tick zs (x:xs) = tack (add p x zs) (filter p xs&) if thunkp xs
+ rule #1: tick zs (x:xs) = tick (add p x zs) xs
+ rule #2: tick zs [] = tack zs []
+ rule #3: tick _ xs = throw (bad_list_value xs)
state 0: #0 #1 #2 #3
<var> state 1
state 1: #0 #1 #2 #3
<var> state 2
- [] state 3
- <app> state 4
+ <app> state 3
+ [] state 13
state 2: #3
- state 3: #0 #3
- state 4: #1 #2 #3
+ state 3: #0 #1 #3
+ <var> state 4
+ <app> state 6
+ state 4: #3
<var> state 5
- <app> state 7
state 5: #3
- <var> state 6
- state 6: #3
- state 7: #1 #2 #3
+ state 6: #0 #1 #3
+ <var> state 7
+ : state 10
+ state 7: #3
<var> state 8
- : state 11
state 8: #3
<var> state 9
state 9: #3
- <var> state 10
- state 10: #3
- state 11: #1 #2 #3
+ state 10: #0 #1 #3
+ <var> state 11
+ state 11: #0 #1 #3
<var> state 12
- state 12: #1 #2 #3
- <var> state 13
- state 13: #1 #2 #3
+ state 12: #0 #1 #3
+ state 13: #2 #3
+}; tack (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tack/*1*/ xs/*0:011*/ (x/*0:0101*/:ys/*0:1*/); tack [] ys/*0:1*/ = ys/*0:1*/ {
+ rule #0: tack (x:xs) ys = tack xs (x:ys)
+ rule #1: tack [] ys = ys
+ state 0: #0 #1
+ <app> state 1
+ [] state 7
+ state 1: #0
+ <app> state 2
+ state 2: #0
+ : state 3
+ state 3: #0
+ <var> state 4
+ state 4: #0
+ <var> state 5
+ state 5: #0
+ <var> state 6
+ state 6: #0
+ state 7: #1
+ <var> state 8
+ state 8: #1
+}; add p/*0:001*/ x/*0:01*/ xs/*0:1*/ = if p/*0:001*/ x/*0:01*/ then x/*0:01*/:xs/*0:1*/ else xs/*0:1*/ {
+ rule #0: add p x xs = if p x then x:xs else xs
+ state 0: #0
+ <var> state 1
+ state 1: #0
+ <var> state 2
+ state 2: #0
+ <var> state 3
+ state 3: #0
} end;
foldl f/*0:001*/ a/*0:01*/ [] = a/*0:01*/;
foldl f/*0:001*/ a/*0:01*/ (x/*0:101*/:xs/*0:11*/) = foldl f/*0:001*/ (f/*0:001*/ a/*0:01*/ x/*0:101*/) xs/*0:11*/;
foldl1 f/*0:01*/ (x/*0:101*/:xs/*0:11*/) = foldl f/*0:01*/ x/*0:101*/ xs/*0:11*/;
foldr f/*0:001*/ a/*0:01*/ [] = a/*0:01*/;
-foldr f/*0:001*/ a/*0:01*/ (x/*0:101*/:xs/*0:11*/) = f/*0:001*/ x/*0:101*/ (foldl (flip f/*0:001*/) a/*0:01*/ (reverse xs/*0:11*/));
-foldr1 f/*0:01*/ [x/*0:101*/] = x/*0:101*/;
-foldr1 f/*0:01*/ (x/*0:101*/:xs/*0:11*/) = f/*0:01*/ x/*0:101*/ (foldl1 (flip f/*0:01*/) (reverse xs/*0:11*/));
-head (x/*0:101*/:xs/*0:11*/) = x/*0:101*/;
-init [x/*0:101*/] = [];
-init (x/*0:101*/:xs/*0:11*/) = accum/*0*/ [x/*0:101*/] xs/*0:11*/ with accum ys/*0:01*/ [x/*0:101*/] = reverse ys/*0:01*/; accum ys/*0:01*/ (x/*0:101*/:xs/*0:11*/) = accum/*1*/ (x/*0:101*/:ys/*0:01*/) xs/*0:11*/; accum ys/*0:01*/ xs/*0:1*/ = reverse ys/*0:01*/+init xs/*0:1*/ {
- rule #0: accum ys [x] = reverse ys
- rule #1: accum ys (x:xs) = accum (x:ys) xs
- rule #2: accum ys xs = reverse ys+init xs
- state 0: #0 #1 #2
+foldr f/*0:001*/ a/*0:01*/ xs@(_/*0:101*/:_/*0:11*/) = tick/*0*/ [] xs/*0:1*/ with tick zs/*0:01*/ (x/*0:101*/:xs/*0:11*/) = tack/*1*/ (x/*0:101*/:zs/*0:01*/) (foldr f/*2:001*/ a/*2:01*/ xs/*1:11*/&) if thunkp xs/*0:11*/; tick zs/*0:01*/ (x/*0:101*/:xs/*0:11*/) = tick/*1*/ (x/*0:101*/:zs/*0:01*/) xs/*0:11*/; tick zs/*0:01*/ [] = tack/*1*/ zs/*0:01*/ a/*1:01*/; tick zs/*0:01*/ xs/*0:1*/ = tack/*1*/ zs/*0:01*/ (foldr f/*1:001*/ a/*1:01*/ xs/*0:1*/) {
+ rule #0: tick zs (x:xs) = tack (x:zs) (foldr f a xs&) if thunkp xs
+ rule #1: tick zs (x:xs) = tick (x:zs) xs
+ rule #2: tick zs [] = tack zs a
+ rule #3: tick zs xs = tack zs (foldr f a xs)
+ state 0: #0 #1 #2 #3
<var> state 1
- state 1: #0 #1 #2
+ state 1: #0 #1 #2 #3
<var> state 2
<app> state 3
- state 2: #2
- state 3: #0 #1 #2
+ [] state 13
+ state 2: #3
+ state 3: #0 #1 #3
<var> state 4
<app> state 6
- state 4: #2
+ state 4: #3
<var> state 5
- state 5: #2
- state 6: #0 #1 #2
+ state 5: #3
+ state 6: #0 #1 #3
<var> state 7
: state 10
- state 7: #2
+ state 7: #3
<var> state 8
- state 8: #2
+ state 8: #3
<var> state 9
- state 9: #2
- state 10: #0 #1 #2
+ state 9: #3
+ state 10: #0 #1 #3
<var> state 11
- state 11: #0 #1 #2
+ state 11: #0 #1 #3
<var> state 12
- [] state 13
- state 12: #1 #2
- state 13: #0 #1 #2
+ state 12: #0 #1 #3
+ state 13: #2 #3
+}; tack (x/*0:0101*/:xs/*0:011*/) y/*0:1*/ = tack/*1*/ xs/*0:011*/ (f/*1:001*/ x/*0:0101*/ y/*0:1*/); tack [] y/*0:1*/ = y/*0:1*/ {
+ rule #0: tack (x:xs) y = tack xs (f x y)
+ rule #1: tack [] y = y
+ state 0: #0 #1
+ <app> state 1
+ [] state 7
+ state 1: #0
+ <app> state 2
+ state 2: #0
+ : state 3
+ state 3: #0
+ <var> state 4
+ state 4: #0
+ <var> state 5
+ state 5: #0
+ <var> state 6
+ state 6: #0
+ state 7: #1
+ <var> state 8
+ state 8: #1
} end;
-last [x/*0:101*/] = x/*0:101*/;
-last (x/*0:101*/:xs/*0:11*/) = last xs/*0:11*/;
-map f/*0:01*/ [] = [];
-map f/*0:01*/ (x/*0:101*/:xs/*0:11*/) = accum/*0*/ [f/*0:01*/ x/*0:101*/] xs/*0:11*/ with accum ys/*0:01*/ [] = reverse ys/*0:01*/; accum ys/*0:01*/ (x/*0:101*/:xs/*0:11*/) = accum/*1*/ (f/*1:01*/ x/*0:101*/:ys/*0:01*/) xs/*0:11*/; accum ys/*0:01*/ xs/*0:1*/ = reverse ys/*0:01*/+map f/*1:01*/ xs/*0:1*/ {
- rule #0: accum ys [] = reverse ys
- rule #1: accum ys (x:xs) = accum (f x:ys) xs
- rule #2: accum ys xs = reverse ys+map f xs
+foldr1 f/*0:01*/ [x/*0:101*/] = x/*0:101*/;
+foldr1 f/*0:01*/ xs@(_/*0:101*/:_/*0:11*/) = tick/*0*/ [] xs/*0:1*/ with tick zs/*0:01*/ ys@(_/*0:101*/:xs/*0:11*/) = tack/*1*/ zs/*0:01*/ (foldr1 f/*2:01*/ ys/*1:1*/&) if thunkp xs/*0:11*/; tick zs/*0:01*/ xs/*0:1*/ = case xs/*0:1*/ of [x/*0:01*/] = tack/*2*/ zs/*1:01*/ x/*0:01*/; x/*0:01*/:xs/*0:1*/ = tick/*2*/ (x/*0:01*/:zs/*1:01*/) xs/*0:1*/; _/*0:*/ = tack/*2*/ zs/*1:01*/ (foldr1 f/*2:01*/ xs/*1:1*/) {
+ rule #0: [x] = tack zs x
+ rule #1: x:xs = tick (x:zs) xs
+ rule #2: _ = tack zs (foldr1 f xs)
state 0: #0 #1 #2
<var> state 1
- state 1: #0 #1 #2
- <var> state 2
- [] state 3
- <app> state 4
- state 2: #2
- state 3: #0 #2
- state 4: #1 #2
- <var> state 5
- <app> state 7
- state 5: #2
+ <app> state 2
+ state 1: #2
+ state 2: #0 #1 #2
+ <var> state 3
+ <app> state 5
+ state 3: #2
+ <var> state 4
+ state 4: #2
+ state 5: #0 #1 #2
<var> state 6
+ : state 9
state 6: #2
- state 7: #1 #2
+ <var> state 7
+ state 7: #2
<var> state 8
- : state 11
state 8: #2
- <var> state 9
- state 9: #2
+ state 9: #0 #1 #2
<var> state 10
- state 10: #2
+ state 10: #0 #1 #2
+ <var> state 11
+ [] state 12
state 11: #1 #2
+ state 12: #0 #1 #2
+} end {
+ rule #0: tick zs ys@(_:xs) = tack zs (foldr1 f ys&) if thunkp xs
+ rule #1: tick zs xs = case xs of [x] = tack zs x; x:xs = tick (x:zs) xs; _ = tack zs (foldr1 f xs) end
+ state 0: #0 #1
+ <var> state 1
+ state 1: #0 #1
+ <var> state 2
+ <app> state 3
+ state 2: #1
+ state 3: #0 #1
+ <var> state 4
+ <app> state 6
+ state 4: #1
+ <var> state 5
+ state 5: #1
+ state 6: #0 #1
+ <var> state 7
+ : state 10
+ state 7: #1
+ <var> state 8
+ state 8: #1
+ <var> state 9
+ state 9: #1
+ state 10: #0 #1
+ <var> state 11
+ state 11: #0 #1
<var> state 12
- state 12: #1 #2
- <var> state 13
- state 13: #1 #2
+ state 12: #0 #1
+}; tack (x/*0:0101*/:xs/*0:011*/) y/*0:1*/ = tack/*1*/ xs/*0:011*/ (f/*1:01*/ x/*0:0101*/ y/*0:1*/); tack [] y/*0:1*/ = y/*0:1*/ {
+ rule #0: tack (x:xs) y = tack xs (f x y)
+ rule #1: tack [] y = y
+ state 0: #0 #1
+ <app> state 1
+ [] state 7
+ state 1: #0
+ <app> state 2
+ state 2: #0
+ : state 3
+ state 3: #0
+ <var> state 4
+ state 4: #0
+ <var> state 5
+ state 5: #0
+ <var> state 6
+ state 6: #0
+ state 7: #1
+ <var> state 8
+ state 8: #1
} end;
-scanl f/*0:001*/ a/*0:01*/ [] = [a/*0:01*/];
-scanl f/*0:001*/ a/*0:01*/ (x/*0:101*/:xs/*0:11*/) = accum/*0*/ [a/*0:01*/] (f/*0:001*/ a/*0:01*/ x/*0:101*/) xs/*0:11*/ with accum ys/*0:001*/ a/*0:01*/ [] = reverse (a/*0:01*/:ys/*0:001*/); accum ys/*0:001*/ a/*0:01*/ (x/*0:101*/:xs/*0:11*/) = accum/*1*/ (a/*0:01*/:ys/*0:001*/) (f/*1:001*/ a/*0:01*/ x/*0:101*/) xs/*0:11*/; accum _/*0:001*/ _/*0:01*/ xs/*0:1*/ = throw (bad_list_value xs/*0:1*/) {
- rule #0: accum ys a [] = reverse (a:ys)
- rule #1: accum ys a (x:xs) = accum (a:ys) (f a x) xs
- rule #2: accum _ _ xs = throw (bad_list_value xs)
+head (x/*0:101*/:xs/*0:11*/) = x/*0:101*/;
+init [x/*0:101*/] = [];
+init xs@(_/*0:101*/:_/*0:11*/) = tick/*0*/ [] xs/*0:1*/ with tick zs/*0:01*/ ys@(_/*0:101*/:xs/*0:11*/) = tack/*1*/ zs/*0:01*/ (init ys/*1:1*/&) if thunkp xs/*0:11*/; tick zs/*0:01*/ xs/*0:1*/ = case xs/*0:1*/ of [x/*0:01*/] = tack/*2*/ zs/*1:01*/ []; x/*0:01*/:xs/*0:1*/ = tick/*2*/ (x/*0:01*/:zs/*1:01*/) xs/*0:1*/; _/*0:*/ = tack/*2*/ zs/*1:01*/ (init xs/*1:1*/) {
+ rule #0: [x] = tack zs []
+ rule #1: x:xs = tick (x:zs) xs
+ rule #2: _ = tack zs (init xs)
state 0: #0 #1 #2
<var> state 1
- state 1: #0 #1 #2
- <var> state 2
+ <app> state 2
+ state 1: #2
state 2: #0 #1 #2
<var> state 3
- [] state 4
<app> state 5
state 3: #2
- state 4: #0 #2
- state 5: #1 #2
+ <var> state 4
+ state 4: #2
+ state 5: #0 #1 #2
<var> state 6
- <app> state 8
+ : state 9
state 6: #2
<var> state 7
state 7: #2
- state 8: #1 #2
- <var> state 9
- : state 12
- state 9: #2
+ <var> state 8
+ state 8: #2
+ state 9: #0 #1 #2
<var> state 10
- state 10: #2
+ state 10: #0 #1 #2
<var> state 11
- state 11: #2
- state 12: #1 #2
- <var> state 13
- state 13: #1 #2
- <var> state 14
- state 14: #1 #2
+ [] state 12
+ state 11: #1 #2
+ state 12: #0 #1 #2
+} end {
+ rule #0: tick zs ys@(_:xs) = tack zs (init ys&) if thunkp xs
+ rule #1: tick zs xs = case xs of [x] = tack zs []; x:xs = tick (x:zs) xs; _ = tack zs (init xs) end
+ state 0: #0 #1
+ <var> state 1
+ state 1: #0 #1
+ <var> state 2
+ <app> state 3
+ state 2: #1
+ state 3: #0 #1
+ <var> state 4
+ <app> state 6
+ state 4: #1
+ <var> state 5
+ state 5: #1
+ state 6: #0 #1
+ <var> state 7
+ : state 10
+ state 7: #1
+ <var> state 8
+ state 8: #1
+ <var> state 9
+ state 9: #1
+ state 10: #0 #1
+ <var> state 11
+ state 11: #0 #1
+ <var> state 12
+ state 12: #0 #1
+}; tack (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tack/*1*/ xs/*0:011*/ (x/*0:0101*/:ys/*0:1*/); tack [] ys/*0:1*/ = ys/*0:1*/ {
+ rule #0: tack (x:xs) ys = tack xs (x:ys)
+ rule #1: tack [] ys = ys
+ state 0: #0 #1
+ <app> state 1
+ [] state 7
+ state 1: #0
+ <app> state 2
+ state 2: #0
+ : state 3
+ state 3: #0
+ <var> state 4
+ state 4: #0
+ <var> state 5
+ state 5: #0
+ <var> state 6
+ state 6: #0
+ state 7: #1
+ <var> state 8
+ state 8: #1
} end;
-scanl1 f/*0:01*/ [] = [];
-scanl1 f/*0:01*/ (x/*0:101*/:xs/*0:11*/) = accum/*0*/ [] x/*0:101*/ xs/*0:11*/ with accum ys/*0:001*/ a/*0:01*/ [] = reverse (a/*0:01*/:ys/*0:001*/); accum ys/*0:001*/ a/*0:01*/ (x/*0:101*/:xs/*0:11*/) = accum/*1*/ (a/*0:01*/:ys/*0:001*/) (f/*1:01*/ a/*0:01*/ x/*0:101*/) xs/*0:11*/; accum _/*0:001*/ _/*0:01*/ xs/*0:1*/ = throw (bad_list_value xs/*0:1*/) {
- rule #0: accum ys a [] = reverse (a:ys)
- rule #1: accum ys a (x:xs) = accum (a:ys) (f a x) xs
- rule #2: accum _ _ xs = throw (bad_list_value xs)
- state 0: #0 #1 #2
+last [x/*0:101*/] = x/*0:101*/;
+last (x/*0:101*/:xs/*0:11*/) = last xs/*0:11*/;
+map f/*0:01*/ [] = [];
+map f/*0:01*/ xs@(_/*0:101*/:_/*0:11*/) = tick/*0*/ [] xs/*0:1*/ with tick zs/*0:01*/ (x/*0:101*/:xs/*0:11*/) = tack/*1*/ (f/*1:01*/ x/*0:101*/:zs/*0:01*/) (map f/*2:01*/ xs/*1:11*/&) if thunkp xs/*0:11*/; tick zs/*0:01*/ (x/*0:101*/:xs/*0:11*/) = tick/*1*/ (f/*1:01*/ x/*0:101*/:zs/*0:01*/) xs/*0:11*/; tick zs/*0:01*/ [] = tack/*1*/ zs/*0:01*/ []; tick zs/*0:01*/ xs/*0:1*/ = tack/*1*/ zs/*0:01*/ (map f/*1:01*/ xs/*0:1*/) {
+ rule #0: tick zs (x:xs) = tack (f x:zs) (map f xs&) if thunkp xs
+ rule #1: tick zs (x:xs) = tick (f x:zs) xs
+ rule #2: tick zs [] = tack zs []
+ rule #3: tick zs xs = tack zs (map f xs)
+ state 0: #0 #1 #2 #3
<var> state 1
- state 1: #0 #1 #2
+ state 1: #0 #1 #2 #3
<var> state 2
- state 2: #0 #1 #2
+ <app> state 3
+ [] state 13
+ state 2: #3
+ state 3: #0 #1 #3
+ <var> state 4
+ <app> state 6
+ state 4: #3
+ <var> state 5
+ state 5: #3
+ state 6: #0 #1 #3
+ <var> state 7
+ : state 10
+ state 7: #3
+ <var> state 8
+ state 8: #3
+ <var> state 9
+ state 9: #3
+ state 10: #0 #1 #3
+ <var> state 11
+ state 11: #0 #1 #3
+ <var> state 12
+ state 12: #0 #1 #3
+ state 13: #2 #3
+}; tack (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tack/*1*/ xs/*0:011*/ (x/*0:0101*/:ys/*0:1*/); tack [] ys/*0:1*/ = ys/*0:1*/ {
+ rule #0: tack (x:xs) ys = tack xs (x:ys)
+ rule #1: tack [] ys = ys
+ state 0: #0 #1
+ <app> state 1
+ [] state 7
+ state 1: #0
+ <app> state 2
+ state 2: #0
+ : state 3
+ state 3: #0
+ <var> state 4
+ state 4: #0
+ <var> state 5
+ state 5: #0
+ <var> state 6
+ state 6: #0
+ state 7: #1
+ <var> state 8
+ state 8: #1
+} end;
+scanl f/*0:001*/ a/*0:01*/ [] = [a/*0:01*/];
+scanl f/*0:001*/ a/*0:01*/ xs@(_/*0:101*/:_/*0:11*/) = tick/*0*/ a/*0:01*/ [] xs/*0:1*/ with tick a/*0:001*/ zs/*0:01*/ (x/*0:101*/:xs/*0:11*/) = tack/*1*/ (a/*0:001*/:zs/*0:01*/) (scanl f/*2:001*/ (f/*2:001*/ a/*1:001*/ x/*1:101*/) xs/*1:11*/&) if thunkp xs/*0:11*/; tick a/*0:001*/ zs/*0:01*/ (x/*0:101*/:xs/*0:11*/) = tick/*1*/ (f/*1:001*/ a/*0:001*/ x/*0:101*/) (a/*0:001*/:zs/*0:01*/) xs/*0:11*/; tick a/*0:001*/ zs/*0:01*/ [] = tack/*1*/ zs/*0:01*/ [a/*0:001*/]; tick a/*0:001*/ zs/*0:01*/ xs/*0:1*/ = tack/*1*/ zs/*0:01*/ (scanl f/*1:001*/ a/*0:001*/ xs/*0:1*/) {
+ rule #0: tick a zs (x:xs) = tack (a:zs) (scanl f (f a x) xs&) if thunkp xs
+ rule #1: tick a zs (x:xs) = tick (f a x) (a:zs) xs
+ rule #2: tick a zs [] = tack zs [a]
+ rule #3: tick a zs xs = tack zs (scanl f a xs)
+ state 0: #0 #1 #2 #3
+ <var> state 1
+ state 1: #0 #1 #2 #3
+ <var> state 2
+ state 2: #0 #1 #2 #3
<var> state 3
- [] state 4
- <app> state 5
- state 3: #2
- state 4: #0 #2
- state 5: #1 #2
+ <app> state 4
+ [] state 14
+ state 3: #3
+ state 4: #0 #1 #3
+ <var> state 5
+ <app> state 7
+ state 5: #3
<var> state 6
- <app> state 8
- state 6: #2
- <var> state 7
- state 7: #2
- state 8: #1 #2
+ state 6: #3
+ state 7: #0 #1 #3
+ <var> state 8
+ : state 11
+ state 8: #3
<var> state 9
- : state 12
- state 9: #2
+ state 9: #3
<var> state 10
- state 10: #2
- <var> state 11
- state 11: #2
- state 12: #1 #2
+ state 10: #3
+ state 11: #0 #1 #3
+ <var> state 12
+ state 12: #0 #1 #3
<var> state 13
- state 13: #1 #2
- <var> state 14
- state 14: #1 #2
+ state 13: #0 #1 #3
+ state 14: #2 #3
+}; tack (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tack/*1*/ xs/*0:011*/ (x/*0:0101*/:ys/*0:1*/); tack [] ys/*0:1*/ = ys/*0:1*/ {
+ rule #0: tack (x:xs) ys = tack xs (x:ys)
+ rule #1: tack [] ys = ys
+ state 0: #0 #1
+ <app> state 1
+ [] state 7
+ state 1: #0
+ <app> state 2
+ state 2: #0
+ : state 3
+ state 3: #0
+ <var> state 4
+ state 4: #0
+ <var> state 5
+ state 5: #0
+ <var> state 6
+ state 6: #0
+ state 7: #1
+ <var> state 8
+ state 8: #1
} end;
+scanl1 f/*0:01*/ [] = [];
+scanl1 f/*0:01*/ (x/*0:101*/:xs/*0:11*/) = scanl f/*0:01*/ x/*0:101*/ xs/*0:11*/;
scanr f/*0:001*/ a/*0:01*/ [] = [a/*0:01*/];
-scanr f/*0:001*/ a/*0:01*/ (x/*0:101*/:xs/*0:11*/) = f/*2:001*/ x/*2:101*/ y/*0:01*/:ys/*1:*/ when ys/*0:*/ = reverse (scanl (flip f/*0:001*/) a/*0:01*/ (reverse xs/*0:11*/)); y/*0:01*/:_/*0:1*/ = ys/*0:*/ {
+scanr f/*0:001*/ a/*0:01*/ xs@(_/*0:101*/:_/*0:11*/) = tick/*0*/ [] xs/*0:1*/ with tick zs/*0:01*/ (x/*0:101*/:xs/*0:11*/) = tack/*1*/ zs/*0:01*/ (f/*3:001*/ x/*2:101*/ (y/*0:01*/ when y/*0:01*/:_/*0:1*/ = ys/*1:*/ {
rule #0: y:_ = ys
state 0: #0
<app> state 1
@@ -503,15 +763,80 @@
state 4: #0
<var> state 5
state 5: #0
-} {
- rule #0: ys = reverse (scanl (flip f) a (reverse xs))
+} end)&:ys/*0:*/ when ys/*0:*/ = scanr f/*2:001*/ a/*2:01*/ xs/*1:11*/& {
+ rule #0: ys = scanr f a xs&
state 0: #0
<var> state 1
state 1: #0
+} end) if thunkp xs/*0:11*/; tick zs/*0:01*/ (x/*0:101*/:xs/*0:11*/) = tick/*1*/ (x/*0:101*/:zs/*0:01*/) xs/*0:11*/; tick zs/*0:01*/ [] = tack/*1*/ zs/*0:01*/ [a/*1:01*/]; tick zs/*0:01*/ xs/*0:1*/ = throw (bad_list_value xs/*0:1*/) {
+ rule #0: tick zs (x:xs) = tack zs (f x (y when y:_ = ys end)&:ys when ys = scanr f a xs& end) if thunkp xs
+ rule #1: tick zs (x:xs) = tick (x:zs) xs
+ rule #2: tick zs [] = tack zs [a]
+ rule #3: tick zs xs = throw (bad_list_value xs)
+ state 0: #0 #1 #2 #3
+ <var> state 1
+ state 1: #0 #1 #2 #3
+ <var> state 2
+ <app> state 3
+ [] state 13
+ state 2: #3
+ state 3: #0 #1 #3
+ <var> state 4
+ <app> state 6
+ state 4: #3
+ <var> state 5
+ state 5: #3
+ state 6: #0 #1 #3
+ <var> state 7
+ : state 10
+ state 7: #3
+ <var> state 8
+ state 8: #3
+ <var> state 9
+ state 9: #3
+ state 10: #0 #1 #3
+ <var> state 11
+ state 11: #0 #1 #3
+ <var> state 12
+ state 12: #0 #1 #3
+ state 13: #2 #3
+}; tack (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tack/*2*/ xs/*1:011*/ (f/*2:001*/ x/*1:0101*/ y/*0:01*/:ys/*1:1*/) when y/*0:01*/:_/*0:1*/ = ys/*0:1*/ {
+ rule #0: y:_ = ys
+ state 0: #0
+ <app> state 1
+ state 1: #0
+ <app> state 2
+ state 2: #0
+ : state 3
+ state 3: #0
+ <var> state 4
+ state 4: #0
+ <var> state 5
+ state 5: #0
+} end; tack [] ys/*0:1*/ = ys/*0:1*/ {
+ rule #0: tack (x:xs) ys = tack xs (f x y:ys) when y:_ = ys end
+ rule #1: tack [] ys = ys
+ state 0: #0 #1
+ <app> state 1
+ [] state 7
+ state 1: #0
+ <app> state 2
+ state 2: #0
+ : state 3
+ state 3: #0
+ <var> state 4
+ state 4: #0
+ <var> state 5
+ state 5: #0
+ <var> state 6
+ state 6: #0
+ state 7: #1
+ <var> state 8
+ state 8: #1
} end;
scanr1 f/*0:01*/ [] = [];
scanr1 f/*0:01*/ [x/*0:101*/] = [x/*0:101*/];
-scanr1 f/*0:01*/ (x/*0:101*/:xs/*0:11*/) = f/*2:01*/ x/*2:101*/ y/*0:01*/:ys/*1:*/ when ys/*0:*/ = reverse (scanl1 (flip f/*0:01*/) (reverse xs/*0:11*/)); y/*0:01*/:_/*0:1*/ = ys/*0:*/ {
+scanr1 f/*0:01*/ xs@(_/*0:101*/:_/*0:11*/) = tick/*0*/ [] xs/*0:1*/ with tick zs/*0:01*/ (x/*0:101*/:xs/*0:11*/) = tack/*1*/ zs/*0:01*/ (f/*3:01*/ x/*2:101*/ (y/*0:01*/ when y/*0:01*/:_/*0:1*/ = ys/*1:*/ {
rule #0: y:_ = ys
state 0: #0
<app> state 1
@@ -524,63 +849,170 @@
state 4: #0
<var> state 5
state 5: #0
-} {
- rule #0: ys = reverse (scanl1 (flip f) (reverse xs))
+} end)&:ys/*0:*/ when ys/*0:*/ = scanr1 f/*2:01*/ xs/*1:11*/& {
+ rule #0: ys = scanr1 f xs&
state 0: #0
<var> state 1
state 1: #0
+} end) if thunkp xs/*0:11*/; tick zs/*0:01*/ xs/*0:1*/ = case xs/*0:1*/ of [x/*0:01*/] = tack/*2*/ zs/*1:01*/ [x/*0:01*/]; x/*0:01*/:xs/*0:1*/ = tick/*2*/ (x/*0:01*/:zs/*1:01*/) xs/*0:1*/; _/*0:*/ = throw (bad_list_value xs/*1:1*/) {
+ rule #0: [x] = tack zs [x]
+ rule #1: x:xs = tick (x:zs) xs
+ rule #2: _ = throw (bad_list_value xs)
+ state 0: #0 #1 #2
+ <var> state 1
+ <app> state 2
+ state 1: #2
+ state 2: #0 #1 #2
+ <var> state 3
+ <app> state 5
+ state 3: #2
+ <var> state 4
+ state 4: #2
+ state 5: #0 #1 #2
+ <var> state 6
+ : state 9
+ state 6: #2
+ <var> state 7
+ state 7: #2
+ <var> state 8
+ state 8: #2
+ state 9: #0 #1 #2
+ <var> state 10
+ state 10: #0 #1 #2
+ <var> state 11
+ [] state 12
+ state 11: #1 #2
+ state 12: #0 #1 #2
+} end {
+ rule #0: tick zs (x:xs) = tack zs (f x (y when y:_ = ys end)&:ys when ys = scanr1 f xs& end) if thunkp xs
+ rule #1: tick zs xs = case xs of [x] = tack zs [x]; x:xs = tick (x:zs) xs; _ = throw (bad_list_value xs) end
+ state 0: #0 #1
+ <var> state 1
+ state 1: #0 #1
+ <var> state 2
+ <app> state 3
+ state 2: #1
+ state 3: #0 #1
+ <var> state 4
+ <app> state 6
+ state 4: #1
+ <var> state 5
+ state 5: #1
+ state 6: #0 #1
+ <var> state 7
+ : state 10
+ state 7: #1
+ <var> state 8
+ state 8: #1
+ <var> state 9
+ state 9: #1
+ state 10: #0 #1
+ <var> state 11
+ state 11: #0 #1
+ <var> state 12
+ state 12: #0 #1
+}; tack (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tack/*2*/ xs/*1:011*/ (f/*2:01*/ x/*1:0101*/ y/*0:01*/:ys/*1:1*/) when y/*0:01*/:_/*0:1*/ = ys/*0:1*/ {
+ rule #0: y:_ = ys
+ state 0: #0
+ <app> state 1
+ state 1: #0
+ <app> state 2
+ state 2: #0
+ : state 3
+ state 3: #0
+ <var> state 4
+ state 4: #0
+ <var> state 5
+ state 5: #0
+} end; tack [] ys/*0:1*/ = ys/*0:1*/ {
+ rule #0: tack (x:xs) ys = tack xs (f x y:ys) when y:_ = ys end
+ rule #1: tack [] ys = ys
+ state 0: #0 #1
+ <app> state 1
+ [] state 7
+ state 1: #0
+ <app> state 2
+ state 2: #0
+ : state 3
+ state 3: #0
+ <var> state 4
+ state 4: #0
+ <var> state 5
+ state 5: #0
+ <var> state 6
+ state 6: #0
+ state 7: #1
+ <var> state 8
+ state 8: #1
} end;
tail (x/*0:101*/:xs/*0:11*/) = xs/*0:11*/;
take n/*0:01*/::int [] = [];
-take n/*0:01*/::int (x/*0:101*/:xs/*0:11*/) = accum/*0*/ n/*0:01*/ [] (x/*0:101*/:xs/*0:11*/) with accum _/*0:001*/ ys/*0:01*/ [] = reverse ys/*0:01*/; accum n/*0:001*/::int ys/*0:01*/ _/*0:1*/ = reverse ys/*0:01*/ if n/*0:001*/<=0; accum n/*0:001*/::int ys/*0:01*/ (x/*0:101*/:xs/*0:11*/) = accum/*1*/ (n/*0:001*/-1) (x/*0:101*/:ys/*0:01*/) xs/*0:11*/; accum n/*0:001*/ ys/*0:01*/ xs/*0:1*/ = reverse ys/*0:01*/+take n/*0:001*/ xs/*0:1*/ {
- rule #0: accum _ ys [] = reverse ys
- rule #1: accum n::int ys _ = reverse ys if n<=0
- rule #2: accum n::int ys (x:xs) = accum (n-1) (x:ys) xs
- rule #3: accum n ys xs = reverse ys+take n xs
- state 0: #0 #1 #2 #3
+take n/*0:01*/::int xs@(_/*0:101*/:_/*0:11*/) = tick/*0*/ n/*0:01*/ [] xs/*0:1*/ with tick n/*0:001*/::int zs/*0:01*/ xs/*0:1*/ = tack/*1*/ zs/*0:01*/ [] if n/*0:001*/<=0; tick n/*0:001*/::int zs/*0:01*/ xs/*0:1*/ = case xs/*0:1*/ of [] = tack/*2*/ zs/*1:01*/ []; x/*0:01*/:xs/*0:1*/ = tick/*2*/ (n/*1:001*/-1) (x/*0:01*/:zs/*1:01*/) xs/*0:1*/; _/*0:*/ = tack/*2*/ zs/*1:01*/ (take n/*1:001*/ xs/*1:1*/) {
+ rule #0: [] = tack zs []
+ rule #1: x:xs = tick (n-1) (x:zs) xs
+ rule #2: _ = tack zs (take n xs)
+ state 0: #0 #1 #2
<var> state 1
- <var>::int state 5
- state 1: #0 #3
+ [] state 2
+ <app> state 3
+ state 1: #2
+ state 2: #0 #2
+ state 3: #1 #2
+ <var> state 4
+ <app> state 6
+ state 4: #2
+ <var> state 5
+ state 5: #2
+ state 6: #1 #2
+ <var> state 7
+ : state 10
+ state 7: #2
+ <var> state 8
+ state 8: #2
+ <var> state 9
+ state 9: #2
+ state 10: #1 #2
+ <var> state 11
+ state 11: #1 #2
+ <var> state 12
+ state 12: #1 #2
+} end {
+ rule #0: tick n::int zs xs = tack zs [] if n<=0
+ rule #1: tick n::int zs xs = case xs of [] = tack zs []; x:xs = tick (n-1) (x:zs) xs; _ = tack zs (take n xs) end
+ state 0: #0 #1
+ <var>::int state 1
+ state 1: #0 #1
<var> state 2
- state 2: #0 #3
+ state 2: #0 #1
<var> state 3
- [] state 4
- state 3: #3
- state 4: #0 #3
- state 5: #0 #1 #2 #3
+ state 3: #0 #1
+}; tack (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tack/*1*/ xs/*0:011*/ (x/*0:0101*/:ys/*0:1*/); tack [] ys/*0:1*/ = ys/*0:1*/ {
+ rule #0: tack (x:xs) ys = tack xs (x:ys)
+ rule #1: tack [] ys = ys
+ state 0: #0 #1
+ <app> state 1
+ [] state 7
+ state 1: #0
+ <app> state 2
+ state 2: #0
+ : state 3
+ state 3: #0
+ <var> state 4
+ state 4: #0
+ <var> state 5
+ state 5: #0
<var> state 6
- state 6: #0 #1 #2 #3
- <var> state 7
- [] state 8
- <app> state 9
- state 7: #1 #3
- state 8: #0 #1 #3
- state 9: #1 #2 #3
- <var> state 10
- <app> state 12
- state 10: #1 #3
- <var> state 11
- state 11: #1 #3
- state 12: #1 #2 #3
- <var> state 13
- : state 16
- state 13: #1 #3
- <var> state 14
- state 14: #1 #3
- <var> state 15
- state 15: #1 #3
- state 16: #1 #2 #3
- <var> state 17
- state 17: #1 #2 #3
- <var> state 18
- state 18: #1 #2 #3
+ state 6: #0
+ state 7: #1
+ <var> state 8
+ state 8: #1
} end;
takewhile p/*0:01*/ [] = [];
-takewhile p/*0:01*/ (x/*0:101*/:xs/*0:11*/) = accum/*0*/ [] (x/*0:101*/:xs/*0:11*/) with accum ys/*0:01*/ [] = reverse ys/*0:01*/; accum ys/*0:01*/ (x/*0:101*/:xs/*0:11*/) = accum/*1*/ (x/*0:101*/:ys/*0:01*/) xs/*0:11*/ if p/*1:01*/ x/*0:101*/; accum ys/*0:01*/ (x/*0:101*/:xs/*0:11*/) = reverse ys/*0:01*/; accum ys/*0:01*/ xs/*0:1*/ = reverse ys/*0:01*/+takewhile p/*1:01*/ xs/*0:1*/ {
- rule #0: accum ys [] = reverse ys
- rule #1: accum ys (x:xs) = accum (x:ys) xs if p x
- rule #2: accum ys (x:xs) = reverse ys
- rule #3: accum ys xs = reverse ys+takewhile p xs
+takewhile p/*0:01*/ xs@(_/*0:101*/:_/*0:11*/) = tick/*0*/ [] xs/*0:1*/ with tick zs/*0:01*/ [] = tack/*1*/ zs/*0:01*/ []; tick zs/*0:01*/ (x/*0:101*/:xs/*0:11*/) = tick/*1*/ (x/*0:101*/:zs/*0:01*/) xs/*0:11*/ if p/*1:01*/ x/*0:101*/; tick zs/*0:01*/ (x/*0:101*/:xs/*0:11*/) = tack/*1*/ zs/*0:01*/ []; tick zs/*0:01*/ xs/*0:1*/ = tack/*1*/ zs/*0:01*/ (takewhile p/*1:01*/ xs/*0:1*/) {
+ rule #0: tick zs [] = tack zs []
+ rule #1: tick zs (x:xs) = tick (x:zs) xs if p x
+ rule #2: tick zs (x:xs) = tack zs []
+ rule #3: tick zs xs = tack zs (takewhile p xs)
state 0: #0 #1 #2 #3
<var> state 1
state 1: #0 #1 #2 #3
@@ -608,74 +1040,113 @@
state 12: #1 #2 #3
<var> state 13
state 13: #1 #2 #3
+}; tack (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tack/*1*/ xs/*0:011*/ (x/*0:0101*/:ys/*0:1*/); tack [] ys/*0:1*/ = ys/*0:1*/ {
+ rule #0: tack (x:xs) ys = tack xs (x:ys)
+ rule #1: tack [] ys = ys
+ state 0: #0 #1
+ <app> state 1
+ [] state 7
+ state 1: #0
+ <app> state 2
+ state 2: #0
+ : state 3
+ state 3: #0
+ <var> state 4
+ state 4: #0
+ <var> state 5
+ state 5: #0
+ <var> state 6
+ state 6: #0
+ state 7: #1
+ <var> state 8
+ state 8: #1
} end;
cat [] = [];
-cat [xs/*0:101*/] = xs/*0:101*/;
-cat (xs/*0:101*/:xss/*0:11*/) = accum/*0*/ (reverse xs/*0:101*/) xss/*0:11*/ with accum xs/*0:01*/ [] = reverse xs/*0:01*/; accum xs/*0:01*/ ([]:yss/*0:11*/) = accum/*1*/ xs/*0:01*/ yss/*0:11*/; accum xs/*0:01*/ ((y/*0:10101*/:ys/*0:1011*/):yss/*0:11*/) = accum/*1*/ (y/*0:10101*/:xs/*0:01*/) (ys/*0:1011*/:yss/*0:11*/); accum _/*0:01*/ (ys/*0:101*/:_/*0:11*/) = throw (bad_list_value ys/*0:101*/); accum _/*0:01*/ yss/*0:1*/ = throw (bad_list_value yss/*0:1*/) {
- rule #0: accum xs [] = reverse xs
- rule #1: accum xs ([]:yss) = accum xs yss
- rule #2: accum xs ((y:ys):yss) = accum (y:xs) (ys:yss)
- rule #3: accum _ (ys:_) = throw (bad_list_value ys)
- rule #4: accum _ yss = throw (bad_list_value yss)
- state 0: #0 #1 #2 #3 #4
+cat xs@(_/*0:101*/:_/*0:11*/) = foldr ((+/*0*/)) [] xs/*0:1*/ with []+ys/*0:1*/ = ys/*0:1*/; xs@(_/*0:0101*/:_/*0:011*/)+ys/*0:1*/ = tick/*1*/ [] xs/*0:01*/ ys/*0:1*/ {
+ rule #0: []+ys = ys
+ rule #1: xs@(_:_)+ys = tick [] xs ys
+ state 0: #0 #1
+ [] state 1
+ <app> state 3
+ state 1: #0
+ <var> state 2
+ state 2: #0
+ state 3: #1
+ <app> state 4
+ state 4: #1
+ : state 5
+ state 5: #1
+ <var> state 6
+ state 6: #1
+ <var> state 7
+ state 7: #1
+ <var> state 8
+ state 8: #1
+}; tick zs/*0:001*/ (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tack/*1*/ (x/*0:0101*/:zs/*0:001*/) (xs/*1:011*/+/*2*/ys/*1:1*/&) if thunkp xs/*0:011*/; tick zs/*0:001*/ (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tick/*1*/ (x/*0:0101*/:zs/*0:001*/) xs/*0:011*/ ys/*0:1*/; tick zs/*0:001*/ [] ys/*0:1*/ = tack/*1*/ zs/*0:001*/ ys/*0:1*/; tick zs/*0:001*/ xs/*0:01*/ ys/*0:1*/ = tack/*1*/ zs/*0:001*/ (xs/*0:01*/+/*1*/ys/*0:1*/) {
+ rule #0: tick zs (x:xs) ys = tack (x:zs) (xs+ys&) if thunkp xs
+ rule #1: tick zs (x:xs) ys = tick (x:zs) xs ys
+ rule #2: tick zs [] ys = tack zs ys
+ rule #3: tick zs xs ys = tack zs (xs+ys)
+ state 0: #0 #1 #2 #3
<var> state 1
- state 1: #0 #1 #2 #3 #4
+ state 1: #0 #1 #2 #3
<var> state 2
- [] state 3
<app> state 4
- state 2: #4
- state 3: #0 #4
- state 4: #1 #2 #3 #4
+ [] state 17
+ state 2: #3
+ <var> state 3
+ state 3: #3
+ state 4: #0 #1 #3
<var> state 5
- <app> state 7
- state 5: #4
+ <app> state 8
+ state 5: #3
<var> state 6
- state 6: #4
- state 7: #1 #2 #3 #4
- <var> state 8
- : state 11
- state 8: #4
+ state 6: #3
+ <var> state 7
+ state 7: #3
+ state 8: #0 #1 #3
<var> state 9
- state 9: #4
+ : state 13
+ state 9: #3
<var> state 10
- state 10: #4
- state 11: #1 #2 #3 #4
+ state 10: #3
+ <var> state 11
+ state 11: #3
<var> state 12
- [] state 14
- <app> state 16
- state 12: #3 #4
- <var> state 13
- state 13: #3 #4
- state 14: #1 #3 #4
+ state 12: #3
+ state 13: #0 #1 #3
+ <var> state 14
+ state 14: #0 #1 #3
<var> state 15
- state 15: #1 #3 #4
- state 16: #2 #3 #4
- <var> state 17
- <app> state 20
- state 17: #3 #4
+ state 15: #0 #1 #3
+ <var> state 16
+ state 16: #0 #1 #3
+ state 17: #2 #3
<var> state 18
- state 18: #3 #4
- <var> state 19
- state 19: #3 #4
- state 20: #2 #3 #4
- <var> state 21
- : state 25
- state 21: #3 #4
- <var> state 22
- state 22: #3 #4
- <var> state 23
- state 23: #3 #4
- <var> state 24
- state 24: #3 #4
- state 25: #2 #3 #4
- <var> state 26
- state 26: #2 #3 #4
- <var> state 27
- state 27: #2 #3 #4
- <var> state 28
- state 28: #2 #3 #4
+ state 18: #2 #3
+}; tack (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tack/*1*/ xs/*0:011*/ (x/*0:0101*/:ys/*0:1*/); tack [] ys/*0:1*/ = ys/*0:1*/ {
+ rule #0: tack (x:xs) ys = tack xs (x:ys)
+ rule #1: tack [] ys = ys
+ state 0: #0 #1
+ <app> state 1
+ [] state 7
+ state 1: #0
+ <app> state 2
+ state 2: #0
+ : state 3
+ state 3: #0
+ <var> state 4
+ state 4: #0
+ <var> state 5
+ state 5: #0
+ <var> state 6
+ state 6: #0
+ state 7: #1
+ <var> state 8
+ state 8: #1
} end;
-catmap f/*0:01*/ xs/*0:1*/ = cat (map f/*0:01*/ xs/*0:1*/);
+catmap f/*0:01*/ [] = [];
+catmap f/*0:01*/ xs@(_/*0:101*/:_/*0:11*/) = cat (map f/*0:01*/ xs/*0:1*/);
index [] _/*0:1*/ = -1;
index (x/*0:0101*/:xs/*0:011*/) y/*0:1*/ = search/*0*/ 0 (x/*0:0101*/:xs/*0:011*/) with search _/*0:01*/ [] = -1; search n/*0:01*/::int (x/*0:101*/:xs/*0:11*/) = n/*0:01*/ if x/*0:101*/==y/*1:1*/; search n/*0:01*/::int (x/*0:101*/:xs/*0:11*/) = search/*1*/ (n/*0:01*/+1) xs/*0:11*/; search _/*0:01*/ xs/*0:1*/ = index xs/*0:1*/ y/*1:1*/ {
rule #0: search _ [] = -1
@@ -774,309 +1245,545 @@
<var> state 4
state 4: #0 #1
} end;
-zip xs/*0:01*/ ys/*0:1*/ = accum/*0*/ [] xs/*0:01*/ ys/*0:1*/ with accum us/*0:001*/ (x/*0:0101*/:xs/*0:011*/) (y/*0:101*/:ys/*0:11*/) = accum/*1*/ ((x/*0:0101*/,y/*0:101*/):us/*0:001*/) xs/*0:011*/ ys/*0:11*/; accum us/*0:001*/ _/*0:01*/ _/*0:1*/ = reverse us/*0:001*/ {
- rule #0: accum us (x:xs) (y:ys) = accum ((x,y):us) xs ys
- rule #1: accum us _ _ = reverse us
- state 0: #0 #1
+zip [] _/*0:1*/ = [];
+zip _/*0:01*/ [] = [];
+zip xs@(_/*0:0101*/:_/*0:011*/) ys@(_/*0:101*/:_/*0:11*/) = tick/*0*/ [] xs/*0:01*/ ys/*0:1*/ with tick us/*0:001*/ (x/*0:0101*/:xs/*0:011*/) (y/*0:101*/:ys/*0:11*/) = tack/*1*/ ((x/*0:0101*/,y/*0:101*/):us/*0:001*/) (zip xs/*1:011*/ ys/*1:11*/&) if thunkp xs/*0:011*/||thunkp ys/*0:11*/; tick us/*0:001*/ (x/*0:0101*/:xs/*0:011*/) (y/*0:101*/:ys/*0:11*/) = tick/*1*/ ((x/*0:0101*/,y/*0:101*/):us/*0:001*/) xs/*0:011*/ ys/*0:11*/; tick us/*0:001*/ [] _/*0:1*/ = tack/*1*/ us/*0:001*/ []; tick us/*0:001*/ _/*0:01*/ [] = tack/*1*/ us/*0:001*/ []; tick us/*0:001*/ xs/*0:01*/ ys/*0:1*/ = tack/*1*/ us/*0:001*/ (zip xs/*0:01*/ ys/*0:1*/) {
+ rule #0: tick us (x:xs) (y:ys) = tack ((x,y):us) (zip xs ys&) if thunkp xs||thunkp ys
+ rule #1: tick us (x:xs) (y:ys) = tick ((x,y):us) xs ys
+ rule #2: tick us [] _ = tack us []
+ rule #3: tick us _ [] = tack us []
+ rule #4: tick us xs ys = tack us (zip xs ys)
+ state 0: #0 #1 #2 #3 #4
<var> state 1
- state 1: #0 #1
+ state 1: #0 #1 #2 #3 #4
<var> state 2
- <app> state 4
- state 2: #1
+ <app> state 5
+ [] state 31
+ state 2: #3 #4
<var> state 3
- state 3: #1
- state 4: #0 #1
- <var> state 5
- <app> state 8
- state 5: #1
+ [] state 4
+ state 3: #4
+ state 4: #3 #4
+ state 5: #0 #1 #3 #4
<var> state 6
- state 6: #1
+ <app> state 10
+ state 6: #3 #4
<var> state 7
- state 7: #1
- state 8: #0 #1
- <var> state 9
- : state 13
- state 9: #1
- <var> state 10
- state 10: #1
+ state 7: #3 #4
+ <var> state 8
+ [] state 9
+ state 8: #4
+ state 9: #3 #4
+ state 10: #0 #1 #3 #4
<var> state 11
- state 11: #1
+ : state 16
+ state 11: #3 #4
<var> state 12
- state 12: #1
- state 13: #0 #1
+ state 12: #3 #4
+ <var> state 13
+ state 13: #3 #4
<var> state 14
- state 14: #0 #1
- <var> state 15
- state 15: #0 #1
- <var> state 16
- <app> state 17
- state 16: #1
- state 17: #0 #1
+ [] state 15
+ state 14: #4
+ state 15: #3 #4
+ state 16: #0 #1 #3 #4
+ <var> state 17
+ state 17: #0 #1 #3 #4
<var> state 18
+ state 18: #0 #1 #3 #4
+ <var> state 19
<app> state 20
- state 18: #1
- <var> state 19
- state 19: #1
- state 20: #0 #1
+ [] state 30
+ state 19: #4
+ state 20: #0 #1 #4
<var> state 21
- : state 24
- state 21: #1
+ <app> state 23
+ state 21: #4
<var> state 22
- state 22: #1
- <var> state 23
- state 23: #1
- state 24: #0 #1
+ state 22: #4
+ state 23: #0 #1 #4
+ <var> state 24
+ : state 27
+ state 24: #4
<var> state 25
- state 25: #0 #1
+ state 25: #4
<var> state 26
- state 26: #0 #1
+ state 26: #4
+ state 27: #0 #1 #4
+ <var> state 28
+ state 28: #0 #1 #4
+ <var> state 29
+ state 29: #0 #1 #4
+ state 30: #3 #4
+ state 31: #2 #3 #4
+ <var> state 32
+ [] state 33
+ state 32: #2 #4
+ state 33: #2 #3 #4
+}; tack (u/*0:0101*/:us/*0:011*/) vs/*0:1*/ = tack/*1*/ us/*0:011*/ (u/*0:0101*/:vs/*0:1*/); tack [] vs/*0:1*/ = vs/*0:1*/ {
+ rule #0: tack (u:us) vs = tack us (u:vs)
+ rule #1: tack [] vs = vs
+ state 0: #0 #1
+ <app> state 1
+ [] state 7
+ state 1: #0
+ <app> state 2
+ state 2: #0
+ : state 3
+ state 3: #0
+ <var> state 4
+ state 4: #0
+ <var> state 5
+ state 5: #0
+ <var> state 6
+ state 6: #0
+ state 7: #1
+ <var> state 8
+ state 8: #1
} end;
-zip3 xs/*0:001*/ ys/*0:01*/ zs/*0:1*/ = accum/*0*/ [] xs/*0:001*/ ys/*0:01*/ zs/*0:1*/ with accum us/*0:0001*/ (x/*0:00101*/:xs/*0:0011*/) (y/*0:0101*/:ys/*0:011*/) (z/*0:101*/:zs/*0:11*/) = accum/*1*/ ((x/*0:00101*/,y/*0:0101*/,z/*0:101*/):us/*0:0001*/) xs/*0:0011*/ ys/*0:011*/ zs/*0:11*/; accum us/*0:0001*/ _/*0:001*/ _/*0:01*/ _/*0:1*/ = reverse us/*0:0001*/ {
- rule #0: accum us (x:xs) (y:ys) (z:zs) = accum ((x,y,z):us) xs ys zs
- rule #1: accum us _ _ _ = reverse us
- state 0: #0 #1
+zip3 [] _/*0:01*/ _/*0:1*/ = [];
+zip3 _/*0:001*/ [] _/*0:1*/ = [];
+zip3 _/*0:001*/ _/*0:01*/ [] = [];
+zip3 xs@(_/*0:00101*/:_/*0:0011*/) ys@(_/*0:0101*/:_/*0:011*/) zs@(_/*0:101*/:_/*0:11*/) = tick/*0*/ [] xs/*0:001*/ ys/*0:01*/ zs/*0:1*/ with tick us/*0:0001*/ (x/*0:00101*/:xs/*0:0011*/) (y/*0:0101*/:ys/*0:011*/) (z/*0:101*/:zs/*0:11*/) = tack/*1*/ ((x/*0:00101*/,y/*0:0101*/,z/*0:101*/):us/*0:0001*/) (zip3 xs/*1:0011*/ ys/*1:011*/ zs/*1:11*/&) if thunkp xs/*0:0011*/||thunkp ys/*0:011*/||thunkp zs/*0:11*/; tick us/*0:0001*/ (x/*0:00101*/:xs/*0:0011*/) (y/*0:0101*/:ys/*0:011*/) (z/*0:101*/:zs/*0:11*/) = tick/*1*/ ((x/*0:00101*/,y/*0:0101*/,z/*0:101*/):us/*0:0001*/) xs/*0:0011*/ ys/*0:011*/ zs/*0:11*/; tick us/*0:0001*/ [] _/*0:01*/ _/*0:1*/ = tack/*1*/ us/*0:0001*/ []; tick us/*0:0001*/ _/*0:001*/ [] _/*0:1*/ = tack/*1*/ us/*0:0001*/ []; tick us/*0:0001*/ _/*0:001*/ _/*0:01*/ [] = tack/*1*/ us/*0:0001*/ []; tick us/*0:0001*/ xs/*0:001*/ ys/*0:01*/ zs/*0:1*/ = tack/*1*/ us/*0:0001*/ (zip3 xs/*0:001*/ ys/*0:01*/ zs/*0:1*/) {
+ rule #0: tick us (x:xs) (y:ys) (z:zs) = tack ((x,y,z):us) (zip3 xs ys zs&) if thunkp xs||thunkp ys||thunkp zs
+ rule #1: tick us (x:xs) (y:ys) (z:zs) = tick ((x,y,z):us) xs ys zs
+ rule #2: tick us [] _ _ = tack us []
+ rule #3: tick us _ [] _ = tack us []
+ rule #4: tick us _ _ [] = tack us []
+ rule #5: tick us xs ys zs = tack us (zip3 xs ys zs)
+ state 0: #0 #1 #2 #3 #4 #5
<var> state 1
- state 1: #0 #1
+ state 1: #0 #1 #2 #3 #4 #5
<var> state 2
- <app> state 5
- state 2: #1
+ <app> state 9
+ [] state 63
+ state 2: #3 #4 #5
<var> st...
[truncated message content] |