Typesafe MRef with a regular monad

Derek Elkins ddarius@hotpop.com
Tue, 10 Jun 2003 15:28:15 -0400


On Tue, 10 Jun 2003 11:44:45 -0700 (PDT)
oleg@pobox.com wrote:

> 
> > update  :: (Typable b) => FM k -> Key k a -> b -> (FM ...)
> 
> I didn't know constraints on values are allowed... Given below is the
> implementation of the required interface, in Haskell98

They aren't presumably as that would (as you and another have shown)
make the implementation more or less trivial.  With constraints
you can have a type a -> b (the type of unsafeCoerce) only it's
meaningful and safe as the values are constrained (as opposed to saying
'give me anything and I'll give you whatever you want')  The question
(at least to me) is more, 'you can satisfy the RefMonad interface with
STRefs or IORefs, but those use "imperative" features under the hood;
can it be satisfied without them?'  Personally, I think Tim Sweeney is
focusing on the wrong aspect.  The problem here has nothing to do with
monads, it's purely a typing issue, you can have monads in Scheme and
you could definitely satisfy that interface (in the pure subset) as
implicitly everything is in class Typeable.  Simon PJ pointed this out
best by changing the question to how to make a "polymorphic" finite map.
 That's not to say that arrows, comonads, or monads, or something else
don't have a place (they might not though) as STRefs/IORefs are only
type safe because they are in a monad, or perhaps you can look at it
another way and they aren't safe at all but monads simply make it
impossible to abuse them, in which case unsafeCoerce is likely the
minimal extension, again this just shows that this is purely a type
issue, unsafeCoerce has nothing to do with monads and I don't think most
would consider it an imperative feature (though a common feature in
imperative languages ;).