From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by margaux.inria.fr, Wed, 28 Oct 92 10:01:51 +0100 Received: from concorde.inria.fr by margaux.inria.fr, Tue, 27 Oct 92 20:40:41 +0100 Received: from LINC.CIS.UPENN.EDU by concorde.inria.fr; Tue, 27 Oct 92 20:43:16 +0100 Received: from ENIAC.SEAS.UPENN.EDU by linc.cis.upenn.edu id AA19991; Tue, 27 Oct 92 14:42:32 -0500 Return-Path: Received: by eniac.seas.upenn.edu id AA00591; Tue, 27 Oct 92 14:42:31 EST Date: Tue, 27 Oct 92 14:42:31 EST From: hedden@eniac.seas.upenn.edu (Jerry Hedden) Posted-Date: Tue, 27 Oct 92 14:42:31 EST Message-Id: <9210271942.AA00591@eniac.seas.upenn.edu> To: caml-list@margaux Subject: Infinite Streams in Caml Light 0.5 Sender: weis@margaux There is a point concerning streams in Caml Light that is not dealt with in the manual. This involves the use of function calls in stream patterns. Such calls are not evaluated in a lazy manner, and can cause the system to crash when a recursive function is used on infinite streams. For example, the following function is intended to map a function over all the elements of a stream: let rec map_stream func = function [< 'x; (map_stream func) strm >] -> [< '(func x); strm >] | [< >] -> [< >] ;; However, as indicated above, if `strm' is infinite, evaluation of the recursive call progresses ad infinitum until "out of memory" occurs. A version of the function that does work on infinite streams is: let rec map_stream func = function [< 'x; strm >] -> [< '(func x); map_stream func strm >] | [< >] -> [< >] ;; In summary, caution is advised when working with function calls on infinite streams. (Of course, we already knew that. Didn't we? ;-) Jerry D. Hedden hedden@esdsdf.dnet.ge.com