Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

mk_istream

Lib.mk_istream : ('a -> 'a) -> 'a -> ('a -> 'b) -> ('a,'b) istream

Create a stream.

An application mk_istream trans init proj creates an imperative stream of elements. The stream is generated by applying trans to the state. The first element in the stream state is init. The value of the state is obtained by applying proj.

Failure

If an application of trans or proj fails when applied to the state.

Example

The following creates a stream of distinct strings.

   - mk_istream (fn x => x+1) 0 (concat "gsym" o int_to_string);
   > val it = <istream> : (int, string) istream

Comments

It is aesthetically unpleasant that the underlying implementation type is visible.

See any book on ML programming to see how functional streams are built.

See also

Lib.next, Lib.state, Lib.reset