(************************************************************ lib_sequence.ml Created : Fri Feb 22 00:42:54 2002 Last modified: Wed Feb 27 23:46:34 2002 Compile: make # ************************************************************) exception Empty open Lazy type 'a delayed = 'a Lazy.status ref type 'a seq = Nil | Sequence of ('a * ('a seq) delayed) let head = function Sequence (a,_) -> (* 11916 *) a | _ -> (* 0 *) raise Empty let tail = function Sequence (_,b) -> (* 11905 *) force b | _ -> (* 0 *) raise Empty let nil = Nil let is_empty = function Nil -> (* 0 *) true | _ -> (* 0 *) false let cons a b = (* 12118 *) Sequence(a,b) let rec take stream n = (* 0 *) if n = 0 then (* 0 *) [] else (* 0 *) match stream with Sequence (a,b) -> (* 0 *) a::(take (force b) (n-1)) | _ -> (* 0 *) raise Empty let rec nth n stream = (* 200 *) if n = 0 then (* 2 *) head stream else (* 198 *) nth (n-1) (tail stream)