[Haskell-cafe] Re: Lazy IO and closing of file handles
Lennart Augustsson
lennart at augustsson.net
Mon Mar 19 16:44:47 EDT 2007
Here's what happens:
fix has type (x->x)->x
and that has to match the first argument to flip, namely 'a->b->c'.
The only chance of that is if x is actually a function type.
Pick x=b->c, now we have
fix has type ((b->c)->b->c)->b->c
and it matches a->b->c if a=(b->c)->b->c
Flip returns b->a->c, and if we substitute we get
b->((b->c)->b->c)->c
If you rename the variables you get the suggested type.
-- Lennart
On Mar 19, 2007, at 20:35 , Pete Kazmier wrote:
> Bryan O'Sullivan <bos at serpentine.com> writes:
>
>> Pete Kazmier wrote:
>>
>>> 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.
>
>> As to why it's okay to call "flip" on "fix" at all, look at the types
>> involved.
>>
>> fix :: (a -> a) -> a
>> flip :: (a -> b -> c) -> b -> a -> c
>>
>> By substitution:
>>
>> flip fix :: a -> ((a -> b) -> a -> b) -> b
>
> Sadly, I'm still confused. I understand how 'flip' works in the case
> where its argument is a function that takes two arguments. I've
> started to use this in my own code lately. But my brain refuses to
> understand how 'flip' is applied to 'fix', a function that takes one
> argument only, which happens to be a function itself. What is 'flip'
> flipping when the function passed to it only takes one argument?
>
> Thanks,
> Pete
>
> _______________________________________________
> 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