Hi!
For monads like the `IO' monad, is there any reason for not providing
a monad operator wrapping the fixpoint combinator into the monad? I
mean a function
fixM :: (a -> M a) -> M a
for some monad `M', which feeds its argument the result eventually
produced by the overall monadic computation. So, something like
fixM (\x -> unitM (1:x))
provides the same *cyclic* data structure (within the monad) as would
unitM (let x = 1:x in x)
Actually, such an operator is provided in GHC's libraries for `ST' and
`PrimIO' (called `fixST' and `fixPrimIO' -- defined in the modules
`PreludeGlaST' and `PreludePrimIO'), but it is not defined for `IO' in
Haskell 1.3.
Sometimes such an operator can be useful -- I just wanted to use it
-- and it is impossible to define the thing for yourself (if you don't
have access to the internals of the monad). Are there any good reasons
not to add it to `IO'?
With regard to adding the thing to the monad classes of Haskell 1.3, I
think that is probably be too much fuss. The operation can probably
not be defined for some monads -- (a) otherwise, the monad laws
wouldn't be complete and (b) I don't know a sensible way to define it
for the list monad. But there are monads in `MonadZero' and
`MonadPlus' which allow such a fixpoint operation, namely `Maybe'.
Any opinions?
Cheers,
Manuel