Class ATs Question
Ashley Yakeley
ashley at semantic.org
Sat Apr 29 14:07:32 EDT 2006
In article
<r02010400-1046-4B28DF02D73311DA9B60001451045A8A@[10.0.1.3]>,
Dave Menendez <dave at zednenem.com> wrote:
> This is one of the motivating examples for associated types. You would
> define Ref as,
>
> class (Monad m) => Ref m where
> data Ref m a
>
> newRef :: a -> m (Ref m a)
> readRef :: Ref m a -> m a
> writeRef :: Ref m a -> a -> m ()
>
> This declares a one-to-one relation between "m" and "Ref m". That is,
> you are guaranteed that Ref (ST s1) == Ref (ST s2) iff s1 == s2.
You can also do it without associated types or MPTCs:
data Ref m a = MkRef
{
readRef :: m a
writeRef :: a -> m ()
}
class (Monad m) => Ref m where
newRef :: a -> m (Ref m a)
This is also more general.
--
Ashley Yakeley, Seattle WA
WWEWDD? http://www.cs.utexas.edu/users/EWD/
More information about the Haskell-prime
mailing list