While trying to follow Alice Manual - A Tour to Wonderland
(http://www.ps.uni-sb.de/alice/manual/tour.html), I got stuck at the
following part in the manual, and was unable to proceed further:
> Here is a lazy version of the zip function:
>
> fun lazy zipz (x::xs, y::ys) = (x,y) :: zipz (xs,ys)
> | zipz _ = nil
> val zipz : 'a list * 'b list -> ('a * 'b) list = _fn
>
> It is possible to calculate the stream of Fibonacci numbers using mapz and
> zipz:
>
> val rec fibs = 1 :: 1 :: (lazy mapz op+ (zipz (fibs, tl fibs)))
> val it : int list = 1 :: 1 :: _lazy
Unfortunately, when I actually typed
> val rec fibs = 1 :: 1 :: (lazy mapz op+ (zipz (fibs, tl fibs)))
into Alice, this is what happened:
> 1.15-1.63: recursive declaration's right-hand side is not a value
I checked the documentation, but was unable to solve this problem. Any
idea on what is wrong?
Also, I discovered the following bug in the manual:
> We can define a lazy variant of the map function:
>
> fun mapz f xs = lazy (case xs of nil => nil
> | x::xs' => f x :: mapz f xs')
> val mapz : ('a -> 'b) -> 'a list -> 'b list = _fn
Unfortunately, when I actually typed the above definition of mapz into
Alice, Alice returned an error message, as follows:
> 2.40-2.40: syntax error found at DARROW
After consulting the "Laziness" section of the Alice Manual - Futures
(http://www.ps.uni-sb.de/alice/manual/futures.html#lazy), I discovered
what seemed a relevant example:
> fun mapz f xs = lazy (case xs of
> [] => nil
> | x::xs => f x :: mapz f xs)
I applied the above example, and modified the previous example as
follows, achieving the expected output:
> > fun mapz f xs = lazy (case xs of
> [] => nil
> | x::xs => f x :: mapz f xs);
> val mapz : ('a -> 'b) -> 'a list -> 'b list = _fn
It seems that the single-quotes ('s) were the source of the problem.
If anybody knows how to solve the earlier-mentioned problem of
overcoming
> val rec fibs = 1 :: 1 :: (lazy mapz op+ (zipz (fibs, tl fibs)));
> 1.15-1.63: recursive declaration's right-hand side is not a value
and achieving
> val rec fibs = 1 :: 1 :: (lazy mapz op+ (zipz (fibs, tl fibs)))
> val it : int list = 1 :: 1 :: _lazy
please let me know.
-- Benjamin L. Russell
_______________________________________________
alice-users mailing list
[email protected]
http://www.ps.uni-sb.de/mailman/listinfo/alice-users