On Sunday 20 June 2010 9:24:54 pm Alexander Solla wrote: > Why can't you just use let notation do deal with the recursion? I > thought "lets" in do blocks were just a little bit of syntactic sugar > for "regular" let expressions, which do allow mutual recursion. I > could be totally wrong though. I'm thinking of something like: > > do a <- getChar > let b = c >>= return . f > let c = b >>= return . g > c >>= putChar > b
This is not what recursive do does. For instance: do rec l <- (:l) <$> getChar return l will read one character, and return an infinite list with that character as the elements. By contrast: let l = (:) <$> getChar <*> l in l will, for one, never complete, and two, call getChar an infinite number of times. In general, it is based on the fixed point: mfix :: (MonadFix m) => (a -> m a) -> m a where the function given may not be separable into a pure function and return at all, which is what would be necessary to implement using let, via the identity: mfix (return . f) = return (fix f) The implementation of mfix is specific to the 'm' in question, not something you can write for all monads. -- Dan _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe