Benjamin L. Russell wrote:
> 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
>>
Indeed, thanks for pointing this out. We restricted the definition of
value expressions at some point (IIRC, because there were problems with
the jitter). Apparently, we forgot to adapt some parts of the manual. I
entered a bug report.
You can work around this limitation by using the (much more general)
mechanism of promises:
- open Promise;
[...]
- val p = promise ();
val p : '1 promise = promise{|_future|}
- val fibs = future p;
val fibs : '2 = _future
- fulfill (p, 1 :: 1 :: (lazy mapz op+ (zipz (fibs, tl fibs))));
val it : unit = ()
- fibs;
val it : int list = 1 :: 1 :: _lazy
If you need recursive constructions like that more often you could write
a simple fixpoint combinator:
- fun fix f =
let val p = promise ()
val x = future p
in
fulfill (p, f x); x
end;
val fix : ('a -> 'a) -> 'a = _fn
- fix (fn fibs => 1 :: 1 :: (lazy mapz op+ (zipz (fibs, tl fibs))));
val it : int list = 1 :: 1 :: _lazy
See the manual page on futures or
http://www.ps.uni-sb.de/alice/manual/library/promise.html for
documentation of the Promise structure.
> 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
>>
Mh, that works fine for me. Are you sure you pasted the code correctly?
(The ticks shouldn't be a problem.)
Best,
- Andreas
_______________________________________________
alice-users mailing list
[email protected]
http://www.ps.uni-sb.de/mailman/listinfo/alice-users