Reference types

Ashley Yakeley ashley@semantic.org
Thu, 7 Feb 2002 01:25:16 -0800


At 2002-02-05 16:54, I wrote:

>    data Ref m a = MkRef
>        {
>        get :: m a,
>        set :: a -> m (),
>        modify :: (a -> a) -> m ()
>        };

Better,

    data Ref m a = MkRef
        {
        get :: m a,
        set :: a -> m ()
        };

    modify :: (Monad m) => Ref m a -> (a -> a) -> m ();
    modify ref map = (get ref) >>= ((set ref) . map);


-- 
Ashley Yakeley, Seattle WA