Date: Mon, 15 Mar 1999 10:06:45 +0100
Message-Id: <199903150906.KAA29053@lsun565.lannion.cnet.fr>
From: Jean-Francois Monin <JeanFrancois.Monin@cnet.francetelecom.fr>
To: Alexey Nogin <nogin@cs.cornell.edu>
Subject: Re: List.filter in Ocaml 2.02
In-Reply-To: <36E95F00.129D35DB@CS.Cornell.EDU>
        <36E854D1.E52CD73B@CS.Cornell.EDU>
Alexey Nogin wrote :
 > > exception Identity
 > >
 > > let share f x = try f x with Identity -> x
 > >
 > > let filter f l =
 > >  let rec fil = function
 > >    | [] -> raise Identity
 > >    | h :: t ->
 > >       if f h then h :: fil t else share fil t in
 > >  share fil l
 > [...]
 > 2) Even if the list is not changed, you first allocate the space and put
 > its copy there, then raise an exception and return the old value. That
 > means that you first waste time in memory allocation and then you waste
 > it in garbage collection.
I don't agree, because this construction 
 > >       if f h then h :: fil t else share fil t in
                         ^^
should never be evaluated when Identity is raised in the "fil t"
occurring just after.  At least, if you replace "h :: fil t" with
"h $$ fil t", where
let ($$) x l = x :: l
you get the expected behavior (for mem alloc concerns).
It would be very surprising that the above program behaves not the same.
-- Jean-Francois
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:21 MET