[Haskell-cafe] A question about mfix

Wei Hu weihu at cs.virginia.edu
Tue Jul 29 21:28:06 EDT 2008


What's wrong about giving mfix the following general definition? 


>  mfix :: (a -> m a) -> m a 
>  mfix f = (mfix f) >>= f 


I know it diverges if (>>=) is strict on the first argument. My 
question is, is this definition correct for all lazy monads? The 
documentation (http://haskell.org/ghc/docs/latest/html/libraries/base/ 
Control-Monad-Fix.html#v%3Amfix) says "mfix f executes the action f 
only once, with the eventual output fed back as the input.". So my 
definition looks like a valid one, doesn't it? 

I haven't fully wrapped my head around this monadic fixed-point thing 
yet. So, if you can give an example showing how my definition differs 
from a standard monad, that'll be great. 



More information about the Haskell-Cafe mailing list