    {-# LANGUAGE
            MultiParamTypeClasses,
            FlexibleInstances,
            UndecidableInstances
      #-}

    module Data.StateRef.Instances.Undecidable where

    import Data.StateRef.Types

    -- |Wrap a state reference that supports reading and writing, and add a
    -- potentially thread-unsafe 'ModifyRef' instance.
    newtype UnsafeModifyRef sr = UnsafeModifyRef sr

    instance ReadRef sr m a => ReadRef (UnsafeModifyRef sr) m a where
        readReference :: UnsafeModifyRef sr -> m a
    readReference (UnsafeModifyRef sr
    sr) = sr -> m a
    forall sr (m :: * -> *) a. ReadRef sr m a => sr -> m a
    readReference sr
    sr
    instance WriteRef sr m a => WriteRef (UnsafeModifyRef sr) m a where
        writeReference :: UnsafeModifyRef sr -> a -> m ()
    writeReference (UnsafeModifyRef sr
    sr) = sr -> a -> m ()
    forall sr (m :: * -> *) a. WriteRef sr m a => sr -> a -> m ()
    writeReference sr
    sr
    instance (Monad m, ReadRef sr m a, WriteRef sr m a) => ModifyRef (UnsafeModifyRef sr) m a where
        atomicModifyReference :: forall b. UnsafeModifyRef sr -> (a -> (a, b)) -> m b
    atomicModifyReference   = UnsafeModifyRef sr -> (a -> (a, b)) -> m b
    forall {m :: * -> *} {sr} {t} {a} {b}.
    (Monad m, ReadRef sr m t, WriteRef sr m a) =>
    sr -> (t -> (a, b)) -> m b
    defaultAtomicModifyReference
        modifyReference :: UnsafeModifyRef sr -> (a -> a) -> m ()
    modifyReference         = UnsafeModifyRef sr -> (a -> a) -> m ()
    forall {m :: * -> *} {sr} {t} {a}.
    (Monad m, ReadRef sr m t, WriteRef sr m a) =>
    sr -> (t -> a) -> m ()
    defaultModifyReference