I see the following code in xmonad
package:
-- | Ignore SIGPIPE to avoid termination when a pipe is full, and SIGCHLD to
-- avoid zombie processes, and clean up any extant zombie processes.
installSignalHandlers :: MonadIO m => m ()
installSignalHandlers = io $ do
installHandler openEndedPipe Ignore Nothing
installHandler sigCHLD Ignore Nothing
(try :: IO a -> IO (Either SomeException a))
$ fix $ \more -> do
x <- getAnyProcessStatus False False
when (isJust x) more
return ()
It seems that this fix
functions comes from Data.Function
But I can't understand how it's used here and when would someone use this fix function?
fix
is the fundamental tool used for implementing recursion. It can always be replaced by a recursivelet
-- and vice versa, a recursivelet
can be turned into a call tofix
. In this example,is equivalent to
and is essentially implementing a loop that calls
getAnyProcessStatus False False
until it returnsNothing
.