I'm looking for some streams related tutorial or any other info.
By stream i mean something like this (I don't know exact definition):
open Lazy;;
type 'a stream = Nil | Cons of 'a Lazy.t * 'a stream Lazy.t;;
(* For example stream of 'integers from x' would look like this: *)
let rec intsfrom x =
Cons(lazy x,lazy (intsfrom (x+1)));;
If you know any www/book or anything on this kind of streams please mail me (err...@tlen.pl).
Many thanks.
_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
With camlp4o, you can use the old parser syntax too.
#load "camlp4o.cma";
let rec enum_from n = [< 'n; enum_from (n + 1) >];;
let first_10 = Stream.npeek 10 (enum_from 1);;
Streams are also lazily evaluated. More complex examples can be had
too, and there is the parser keyword to deconstruct streams as well.
You should be able to find more info in the camlp4 manual at the caml
site.
Jonathan
> Hi,
>
> I'm looking for some streams related tutorial or any other info.
> By stream i mean something like this (I don't know exact definition):
>
> open Lazy;;
> type 'a stream = Nil | Cons of 'a Lazy.t * 'a stream Lazy.t;;
>
> (* For example stream of 'integers from x' would look like this: *)
>
> let rec intsfrom x =
> Cons(lazy x,lazy (intsfrom (x+1)));;
>
> If you know any www/book or anything on this kind of streams please mail me (err...@tlen.pl).
> Many thanks.
I call this a lazy list. Anyway, I use the following definition:
type 'a l = Empty | Cons of 'a * 'a t
and 'a t = 'a l lazy_t (* only one lazy object per cell *)
See attachment for the full implementation.
You can manipulate such lists like real lists, only the syntax is less
comfortable. They are different from streams in the sense of the standard
Stream module, which are mutable.
Martin
--
Martin Jambon, PhD
http://martin.jambon.free.fr
Don't forget about Fstream
(http://caml.inria.fr/pub/docs/manual-camlp4/manual008.html#toc30); it
does the same thing as Stream but in a functional manner (and with a
similar syntax, pa_fstream.cmo).
I just posted a link to some stuff on streams in the context of parsing but
you can write intsfrom as:
# #load "camlp4o.cma";;
Camlp4 Parsing version 3.09.2
# let rec intsfrom n = [< 'n; intsfrom(n+1) >];;
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists