Implementing RefMonads in Haskell without ST,IO
Derek Elkins
ddarius@hotpop.com
Thu, 29 May 2003 23:31:40 -0400
On Thu, 29 May 2003 22:48:05 -0500
"Tim Sweeney" <tim@epicgames.com> wrote:
> If it's not possible to implement a typesafe RefMonad instance
> directly in Haskell, without making use of built-in imperative
> features like IO, then doesn't this refute the claims that monads
> implement imperative features functionally?
>
> -Tim
You certainly can have an instance of RefMonad that -simulates-
updateable references. You can't implement this with update inplace
without an update inplace primitive and if Haskell had an update inplace
primitive that you could use anywhere it wouldn't be a pure language.
Monads in Haskell -allow- imperative features and use of imperative
features without breaking the purity of the entire language. Outside a
monadic computation equational reasoning always holds, even when talking
about imperative actions. That monads implement an imperative effect
doesn't mean they implement it the same way an imperative language
would. Of course, the actual implementation doesn't matter so
implementing it imperatively is just as good as implementing it
functionally as far as static semantics go, which is why everything
(IO&ST) works out.