[Haskell-cafe] Re: flip fix and iterate

Pete Kazmier pete-expires-20070513 at kazmier.com
Tue Mar 20 20:17:32 EDT 2007


"Matthew Brecknell" <haskell at brecknell.org> writes:

> Pete Kazmier:
>> I understand the intent of this code, but I am having a hard time
>> understanding the implementation, specifically the combination of
>> 'fix', 'flip', and 'interate'.  I looked up 'fix' and I'm unsure how
>> one can call 'flip' on a function that takes one argument.
>
> I threw that in there because I figured you were up for another
> challenge. :-)

Haskell has a way of making one feel dumb.  This is by far the most
challenging programming language I've ever used.

> It took me ages to get some clue about how to use fix, quite apart from
> combining it with flip. The concept of passing the output of a function
> as one of its parameters ("tying the knot") can be difficult to accept,
> particularly if you haven't studied lambda calculus. 

This is a bit mind boggling.  Do you have any trivial examples that
may help my understanding?

> Note that I could have just written this:
>
>> let iterate a = do
>>   ... iterate a' ...
>> iterate accum

In the meantime, I'm more than happy to claim ignorance and stick with
the above version which is very accessible to us mere mortals.

> So with my use of "flip fix", I'm really just calling fix on the
> anonymous function (\iterate accum -> ...), and then the parameter
> ("accum") is passed to the function returned by fix. So now you just
> need a couple of weeks (or months if you're as slow as me) to
> understand what fix is all about... :-)

I won't try to understand fix just yet, but I'm still confused by the
type of fix:

     fix :: (a -> a) -> a

It appears to me that it takes a function as an argument, and that
function takes a single argument.  So how are you passing fix an
anonymous function taking 2 arguments?  Sorry if I have beaten this
horse to death, but my pea-sized brain is working overtime here.

Thanks for all of the help.

Pete



More information about the Haskell-Cafe mailing list