Reference types
Ashley Yakeley
ashley@semantic.org
Thu, 7 Feb 2002 02:09:12 -0800
At 2002-02-07 01:19, Simon Peyton-Jones wrote:
>1. Have a single built-in type (Ref), rather than two (IORef and
>STRef).
>I don't see how that can be anything other than a Good Thing, can it?
The problem is that your Ref type is primitive, which means users
wouldn't be able to create their own Refs. I suppose the user could
create a Ref2 type, but wouldn't it be easier to do this:
data Ref m a = MkRef
{
get :: m a,
set :: a -> m ()
};
class RefMonad m where
newRef :: a -> m (Ref m a)
This has the advantage of not changing existing library code, only adding
to it. It works out the same for the user as your proposal, only more
general.
The kind of generalisation you are proposing is, in my opinion, best done
explicitly by Haskell. Primitive functions and types should be as simple,
concrete and primitive as possible. Let Haskell do the clever
generalisation stuff.
--
Ashley Yakeley, Seattle WA