[Haskell-cafe] one-way monads

Zsolt SZALAI zs.szalai at gmail.com
Tue May 20 01:54:33 EDT 2008


Now, i'm getting familiar with monads, but there is a little discredit
about one-way monads.
For example, in monads presented in Monads for Functional Programming
by  Philip Wadler, they are all two-way monads, internal data can be
extracted from the monad, and these data, call them state, are in deed
_local_ to a function using the monadic computation, so the state
there is just a little magic, and they are really just functions(as in
a pure language).
An other example is Random. I've figured out, that when initializing a
generator, it uses the actual timestamp and cputime to initialize. If
it wouldnt happen, two distinct uses of Random in a program would
result the same random number sequence.

Here comes IO and one-way monads, where the internal state can not be
extacted, and seems, that the internal data is global to the program.
Hows that could be? Is it just because main::IO() or because the
implementation of IO uses external C functions and there are no
internal state in the monad itself at all?
And why one can not write a function that makes an IO computation and
the return type does not include and IO contructor? It is a feature of
the language and specific to IO, or anybody  could write a monad with
this property(one-way), assuming the implementation does not use
external languages?
Or the one-way property is just that, there is no such functions, that
allow extracting internal data?
Also, is there any other monad, that has the one-way property?


More information about the Haskell-Cafe mailing list