
On Thu, 2009-07-02 at 15:43 +0400, Bulat Ziganshin wrote:
Hello Maciej,
Thursday, July 2, 2009, 3:31:59 PM, you wrote:
class (Monad m, Monoid v) => MonadInput v m where -- | Gets an element from input (line of text [with \n], 4096 bytes, -- or something like that). mzero on end getChunk :: m v class (Monad m, Monoid v) => MonadOutput v m where -- | Puts an element putChunk :: v -> m ()
how about interact function?
Well. As far as I know there is no way of using it with network. Additionally there is hard to put monadic code in it: myFunc :: (MonadInput i, MonadOutput o) => (String -> m a) -> MyMonad i o m [a] If m == IO - which may be a case in normal code it requires unsafePerformIO with all it's problems. In testing I can use pipes and Identity simplifying the whole testing - allowing user to use it's own monads. The other problem is that the order sometimes matters. Consider: main = interact (\x -> "What's your name?\n" ++ "Hello:\n" ++ x) For human being it is annoying but sometimes it is for example against RFC. Regards