[Haskell-beginners] 'Simple' function

Imants Cekusins imantc at gmail.com
Fri Jun 19 12:43:47 UTC 2015


impossible:
asString :: IO String -> String

here is an article which in addition to this thread clarified it for me:
https://wiki.haskell.org/All_About_Monads

search for:
4.3 No way out

The IO monad is a familiar example of a one-way monad in Haskell.
Because you can't escape from the IO monad, it is impossible to write
a function that does a computation in the IO monad but whose result
type does not include the IO type constructor. This means that any
function whose result type does not contain the IO type constructor is
guaranteed not to use the IO monad.
...
There is no way to get rid of the IO type constructor in the signature
of any function that uses it, so the IO type constructor acts as a
kind of tag that identifies all functions that do I/O. Furthermore,
such functions are only useful within the IO monad. So a one-way monad
effectively creates an isolated computational domain in which the
rules of a pure functional language can be relaxed. Functional
computations can move into the domain, but dangerous side-effects and
non-referentially-transparent functions cannot escape from it.


More information about the Beginners mailing list