At 11:00 am +0200 28/4/00, Erik Meijer wrote:
>If you want to play it rough, you could do what ML programmers do and
>explicitely delay and force the computation of currentSecond:
>
>   currentSecond :: () -> Int
>   currentSecond () = second $ unsafePerformIO localDateTime
>
>However, you should cross your fingers that the compiler is not smart enough
>to do common subexepression elimination when it sees the application
>currentSecond () twice!

Of course a smart compiler will spot that any function with a one 
element domain can be memoised as it must always return the same 
value... Or put another way any good fp compiler writer should 
realise that the programmer of a () -> a function is just trying to 
write a procedure, and that is a *bad* (sorry, can't do Erik's accent 
;-)) thing and should not be allowed, so would memoise it just to 
educate the poor soul :-)

(We actually considered implementing the above [and some others] in 
one compiler once just to see how many users complained their 
programs broke. We thought better of it fearing the repercussions of 
angry "pure" FP programmers denied their side-effects!)

Cheers,
        Nigel
-- 
--
Nigel Perry, New Zealand/Utrecht, The Netherlands

Reply via email to