* [Caml-list] mixing fast and [<>] stream: illegal?
@ 2001-11-04 17:59 Stefano Zacchiroli
2001-11-04 19:06 ` Daniel de Rauglaudre
0 siblings, 1 reply; 2+ messages in thread
From: Stefano Zacchiroli @ 2001-11-04 17:59 UTC (permalink / raw)
To: Inria Ocaml Mailing List
From the ocaml 3.02 documentation:
Stream builders
Warning: these functions create streams with fast access; it is
illegal to mix them with streams built with [< >]; would raise
Failure when accessing such mixed streams.
val from : (int -> 'a option) -> 'a t;;
Stream.from f returns a stream built from the function f. To create a
new stream element, the function f is called with the current stream
count. The user function f must return either Some <value> for a
value or None to specify the end of the stream.
I have tried to mix fast and normal streams as follows:
Objective Caml version 3.02
# let i = ref 0;;
val i : int ref = {contents=0}
# let gen (foo:int) =
let nextint = !i in
i:=!i+1;
Some nextint;;
val gen : int -> int option = <fun>
# let s = Stream.from gen;;
val s : int Stream.t = <abstr>
# Stream.next s;;
- : int = 0
# match s with parser [<'1>] -> true | [<>] -> false;;
- : bool = true
# match s with parser [<'1>] -> true | [<>] -> false;;
- : bool = false
Seems to me that no illegal action was performed ...
Am I wrong?
Is really dangerous mixing the two streams?
TIA.
Cheers!
--
Stefano "Zack" Zacchiroli <zack@cs.unibo.it> ICQ# 33538863
Home Page: http://www.cs.unibo.it/~zacchiro
Undergraduate student of Computer Science @ University of Bologna, Italy
- Information wants to be Open -
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] mixing fast and [<>] stream: illegal?
2001-11-04 17:59 [Caml-list] mixing fast and [<>] stream: illegal? Stefano Zacchiroli
@ 2001-11-04 19:06 ` Daniel de Rauglaudre
0 siblings, 0 replies; 2+ messages in thread
From: Daniel de Rauglaudre @ 2001-11-04 19:06 UTC (permalink / raw)
To: caml-list
Hi,
On Sun, Nov 04, 2001 at 06:59:52PM +0100, Stefano Zacchiroli wrote:
> Seems to me that no illegal action was performed ...
> Am I wrong?
> Is really dangerous mixing the two streams?
The doc meant "streams expressions built with [< >]", not parsers. The [< >]
in parsers are stream patterns, not stream expressions. Your code is ok.
What does not work are things like [< '1; Stream.from gen; '2 >].
It is not dangerous, it will just fail:
# let gen i = Some i;;
val gen : 'a -> 'a option = <fun>
# let s = [< '1; Stream.from gen; '2 >];;
val s : int Stream.t = <abstr>
# Stream.next s;;
- : int = 1
# Stream.next s;;
Uncaught exception: Failure "illegal stream concatenation".
--
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-11-04 19:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-04 17:59 [Caml-list] mixing fast and [<>] stream: illegal? Stefano Zacchiroli
2001-11-04 19:06 ` Daniel de Rauglaudre
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox