[Haskell-cafe] advantages of using fix to define rcursive functions

Donald Bruce Stewart dons at cse.unsw.edu.au
Thu Jul 26 03:29:31 EDT 2007

> Hi,
> I read about the usage of "fix" to define recursive functions. Although I
> think that I understood how to use "fix", I still wonder what the
> advantages of "fix" are (as compared to the "conventional" approach to
> define recursive functions).
> Any hints are appreciated.

There's no obvious advantage that I know of, other than being cute.
An example from xmonad:

    allocaXEvent $ \p -> fix $ \again -> do
        more <- checkMaskEvent d enterWindowMask p
        when more again

So actually, I suppose it is useful for small, anonymous recursive definitions.

-- Don

More information about the Haskell-Cafe mailing list