[Haskell-cafe] Cute code [was: The C Equiv of != in Haskell miscommunication thread]

Vincent Kraeutler vincent at kraeutler.net
Tue May 29 09:26:09 EDT 2007


Tomasz Zielonka wrote:
> On Tue, May 29, 2007 at 02:19:31PM +0200, Tomasz Zielonka wrote:
>   
>> On Tue, May 29, 2007 at 12:15:23PM +0200, Vincent Kraeutler wrote:
>>     
>>> ever the interested amateur, i admittedly remain stumped by fix (there's
>>> evidence i'm not the only one [1])
>>>       
>> The above code is equivalent to
>>
>>     let l = 1 : scanl (+) 1 l in l
>>
>> which is a bit easier to decipher.
>>
>> The rest is maths and the subtleties of lazy evaluation.
>>     
> ... and these are the things you need to focus on to understand this
> code. In this case the use of fix is almost a small syntactic issue -
> you can eliminate it by inlining its definition.
>
> Best regards
> Tomek
>
>
>   
i see that the definition of fix (from Control.Monad.Fix) could not be
any simpler:

> fix f = let x = f x in x

same goes for the type:

Prelude> :t Control.Monad.Fix.fix
Control.Monad.Fix.fix :: (a -> a) -> a

it's just that i find it difficult to get concrete intellectual mileage
out of it.
i can reproduce results for specific examples (and even manipulate them
a bit), but feel like i'm missing something deep yet simple. say, i
would not know where and how to apply it. so obviously true
understanding is still missing. reminds me of my first encounters with
$H \psi = E \psi$. ;-)

most likely, i should just more carefully read the references i cited
myself ;-)

anyhow. if someone has a "pedestrian's guide to the fixed point
operator" lying around, a link would be much appreciated.

kind regards,
v.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070529/9b974a13/signature.bin


More information about the Haskell-Cafe mailing list