Monad, more than one of them ?

I am reading "Monads for functional programming" from http://homepages.inf.ed.ac.uk/wadler/topics/monads.html, which is IMO the best explanation of monad I have seen so far. What I would like to know is, what if I need more than one of them at the same time. Using the example given in the paper, it is quite comment that one would need exception handling, state management and output all at the same time. In an imperative language, one can do all three at the same time in the normal flow like wrapping a try/catch block, make some state changes to a global variable and make some io calls. How would one do it in a monadic way ? As my understanding of Monad is that it is something like a "wrapper/container" where the side-effect is kept. One way of doing it is of course expand it to include all three side effects. But this is unmanageable and it is no different than the non-monadic version mentioned in the paper. Another way I can see is to "wrap" one monad with another and so on. But this can also get complicated as what if I have 10 type of monads that can be permutated in various way. ______________________________________________________ Click here to donate to the Hurricane Katrina relief effort. http://store.yahoo.com/redcross-donate3/

Hello gary, Sunday, September 11, 2005, 8:22:50 AM, you wrote: gn> in the paper, it is quite comment that one would need gn> exception handling, state management and output all at gn> the same time. gn> How would one do it in a monadic way ? As my gn> understanding of Monad is that it is something like a gn> "wrapper/container" where the side-effect is kept. One gn> way of doing it is of course expand it to include all gn> three side effects. But this is unmanageable and it is this all done in IO monad, which is just way to order statements sequentially. all other monads give your ability to return pure results, while IO is unescapable (not counting unsafe tricks) and corresponds to events in real world below is my directory of docs for "Imperative programming in GHC". i little reordered it so more interesting docs come first: Tackling the awkward squad: monadic input/output, concurrency, exceptions, and foreign-language calls in Haskell [http://research.microsoft.com/Users/simonpj/papers/marktoberdorf/marktoberdo...] Writing High-Performance Server Applications in Haskell, Case Study: A Haskell Web Server, [http://www.haskell.org/~simonmar/papers/web-server.ps.gz] [http://research.microsoft.com/~simonpj/papers/stm/stm.pdf] [http://www.haskell.org/ghc/docs/papers/except_ps.gz] Asynchronous Exceptions in Haskell [http://www.haskell.org/~simonmar/papers/async.ps.gz] Imperative Functional Programming [http://www.haskell.org/ghc/docs/papers/imperative.ps.gz] [http://www.haskell.org/ghc/docs/papers/concurrent-haskell.ps.gz] [http://research.microsoft.com/Users/simonpj/Papers/unboxed-values.ps.Z] [http://www.cse.unsw.edu.au/~chak/haskell/ffi/ffi.pdf] The Concurrent Haskell Foreign Function Interface [http://www.haskell.org/ghc/docs/papers/threads.ps.gz] [http://www.haskell.org/~simonmar/papers/conc-ffi.pdf] there is a several imperative programs also, of which i recommend to see web server itself (of course) - i don't know url, but it mentioned in secod paper, Postmaster (http://postmaster.cryp.to/postmaster-2005-02-14.tar.gz), my own FreeArc (http://freearc.narod.ru), Yi editor (ftp://ftp.cse.unsw.edu.au/pub/users/dons/yi/yi-0.1.0.tar.gz) -- Best regards, Bulat mailto:bulatz@HotPOP.com

Aside from using a monad which has all the effects you need directly,
or working in the IO monad, you can compose a monad with the necessary
properties using monad transformers (which you tend to then at least
give a type alias to, if not a newtype declaration). Part III of
http://www.nomaware.com/monads/html/ deals with monad transformers,
and shows how various effects can be combined to get just what is
desired.
- Cale
On 11/09/05, gary ng
I am reading "Monads for functional programming" from http://homepages.inf.ed.ac.uk/wadler/topics/monads.html, which is IMO the best explanation of monad I have seen so far.
What I would like to know is, what if I need more than one of them at the same time. Using the example given in the paper, it is quite comment that one would need exception handling, state management and output all at the same time.
In an imperative language, one can do all three at the same time in the normal flow like wrapping a try/catch block, make some state changes to a global variable and make some io calls.
How would one do it in a monadic way ? As my understanding of Monad is that it is something like a "wrapper/container" where the side-effect is kept. One way of doing it is of course expand it to include all three side effects. But this is unmanageable and it is no different than the non-monadic version mentioned in the paper. Another way I can see is to "wrap" one monad with another and so on. But this can also get complicated as what if I have 10 type of monads that can be permutated in various way.
______________________________________________________ Click here to donate to the Hurricane Katrina relief effort. http://store.yahoo.com/redcross-donate3/ _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Bulat Ziganshin
-
Cale Gibbard
-
gary ng