[Haskell-cafe] least fixed points above something

John A. De Goes john at n-brain.net
Thu Mar 19 12:31:24 EDT 2009


A JIT compiler can easily know.

Regards,

John A. De Goes
N-BRAIN, Inc.
The Evolution of Collaboration

http://www.n-brain.net    |    877-376-2724 x 101

On Mar 19, 2009, at 10:29 AM, Neil Mitchell wrote:

> CSE is tricky and a potential space leak in general. I'd love it if
> the compiler could pick the best option, but I'm afraid its unlikely
> to know.
>
> On Thu, Mar 19, 2009 at 4:25 PM, Edsko de Vries <devriese at cs.tcd.ie>  
> wrote:
>> I always feel that the compiler should do such optimizations for  
>> me :)
>> On 19 Mar 2009, at 16:21, Neil Mitchell wrote:
>>
>>>> I've used a similar function myself, but why write it in such a
>>>> complicated
>>>> way? How about
>>>>
>>>> lfp :: Eq a => (a -> a) -> a -> a
>>>> lfp f x
>>>>  | f x == x = x
>>>>  | otherwise = lfp f (f x)
>>>
>>> I've used a similar function too, but your version computes f x  
>>> twice
>>> per iteration, I wrote mine as:
>>>
>>> fix :: Eq a => (a -> a) -> a -> a
>>> fix f x = if x == x2 then x else fix f x2
>>>   where x2 = f x
>>>
>>> I find this fix much more useful than the standard fix.
>>>
>>> Thanks
>>>
>>> Neil
>>
>>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



More information about the Haskell-Cafe mailing list