Version française
Home     About     Download     Resources     Contact us    
Browse thread
log function without evaluate arguments
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Hurt <bhurt@j...>
Subject: Re: [Caml-list] log function without evaluate arguments
Christopher L Conway wrote:

>On 11/6/07, Erik de Castro Lopo <mle+ocaml@mega-nerd.com> wrote:
>  
>
>>Christopher L Conway wrote:
>>
>>    
>>
>>>On 11/6/07, Brian Hurt <bhurt@janestcapital.com> wrote:
>>>      
>>>
>>>> Also, creating a lazy thunk in Ocaml is expensive (like 140+ clock cycles),
>>>>while passing an argument into a function is cheap- and the common case will
>>>>be that the argument won't need to be evaluated, just passed in.
>>>>        
>>>>
>>>What does this mean? Did OCaml become non-strict while I wasn't looking?
>>>      
>>>
>>Ocaml is strict by default and optionally lazy.
>>
>>The code being discussed was this:
>>
>>    log (lazy (Printf.printf "%s" (awfully_long_computation ())))
>>
>>where everything inside
>>
>>    (lazy X)
>>
>>is lazy evaluated.
>>    
>>
>
>Yes, of course. But, if I understand correctly, Brian was arguing in favor of
>
>   Printf.ifprinf "%s" (awfully_long_computation ())
>
>and claiming that it was potentially more efficient than the lazy version.
>
>  
>
No, I was arguing that:

Printf.ifprintf "%s" "foo"

was more efficient, and was a much more common case.

I was also arguing that:

Printf.ifprintf "%s" (awfully_long_computation ())

was more likely to be correct, especially if awfully_long_computation 
includes side effects.

Brian