module Control.Reference.Types where
import Control.Reference.Representation
import Control.Instances.Morph
import Control.Monad
import Control.Monad.State (StateT)
import Control.Monad.Writer (WriterT)
import Control.Monad.Trans.List (ListT(..))
import Control.Monad.Trans.Maybe (MaybeT(..))
import Control.Monad.ST (ST)
import Data.Proxy
type Simple t s a = t s s a a
type Getter r s t a b = Reference MU r MU MU s t a b
type Setter w s t a b = Reference w MU MU MU s t a b
type Iso s t a b
= forall w r w' r' . (RefMonads w r, RefMonads w' r') => Reference w r w' r' s t a b
type Prism s t a b
= forall w r w' r' . (RefMonads w r, RefMonads w' r'
, MonadPlus r, Morph Maybe r
, MonadPlus w', Morph Maybe w')
=> Reference w r w' r' s t a b
type Lens s t a b
= forall w r . RefMonads w r => Reference w r MU MU s t a b
type RefPlus s t a b
= forall w r . ( RefMonads w r, MonadPlus r )
=> Reference w r MU MU s t a b
type Partial s t a b
= forall w r . ( Functor w, Applicative w, Monad w
, Functor r, Applicative r, MonadPlus r, Morph Maybe r )
=> Reference w r MU MU s t a b
type Traversal s t a b
= forall w r . (RefMonads w r, MonadPlus r, Morph Maybe r, Morph [] r )
=> Reference w r MU MU s t a b
type IOMonads w r = ( Morph IO w, Morph IO r
, MorphControl IO w, MorphControl IO r )
type IOLens s t a b
= forall w r . ( RefMonads w r, IOMonads w r )
=> Reference w r MU MU s t a b
type IOPartial s t a b
= forall w r . (RefMonads w r, IOMonads w r, MonadPlus r, Morph Maybe r )
=> Reference w r MU MU s t a b
type IOTraversal s t a b
= forall w r . ( RefMonads w r, IOMonads w r, MonadPlus r, Morph Maybe r, Morph [] r )
=> Reference w r MU MU s t a b
type StateLens st m s t a b
= forall w r . ( RefMonads w r, Morph (StateT st m) w, Morph (StateT st m) r )
=> Reference w r MU MU s t a b
type StatePartial st m s t a b
= forall w r . ( RefMonads w r, Morph (StateT st m) w, MonadPlus r, Morph Maybe r, Morph (StateT st m) r )
=> Reference w r MU MU s t a b
type StateTraversal st m s t a b
= forall w r . ( RefMonads w r, Morph (StateT st m) w, MonadPlus r, Morph Maybe r, Morph [] r, Morph (StateT st m) r )
=> Reference w r MU MU s t a b
type WriterLens st m s t a b
= forall w r . ( RefMonads w r, Morph (WriterT st m) w, Morph (WriterT st m) r )
=> Reference w r MU MU s t a b
type WriterPartial st m s t a b
= forall w r . ( RefMonads w r, Morph (WriterT st m) w, MonadPlus r, Morph Maybe r, Morph (WriterT st m) r )
=> Reference w r MU MU s t a b
type WriterTraversal st m s t a b
= forall w r . ( RefMonads w r, Morph (WriterT st m) w, MonadPlus r, Morph Maybe r, Morph [] r, Morph (WriterT st m) r )
=> Reference w r MU MU s t a b
type STLens st s t a b
= forall w r . ( RefMonads w r, Morph (ST st) w, Morph (ST st) r )
=> Reference w r MU MU s t a b
type STPartial st s t a b
= forall w r . ( RefMonads w r, Morph (ST st) w, MonadPlus r, Morph Maybe r, Morph (ST st) r )
=> Reference w r MU MU s t a b
type STTraversal st s t a b
= forall w r . ( RefMonads w r, Morph (ST st) w, MonadPlus r, Morph Maybe r, Morph [] r, Morph (ST st) r )
=> Reference w r MU MU s t a b
class MorphControl (m1 :: * -> *) (m2 :: * -> *) where
data MSt m1 m2 a :: *
sink :: m2 a -> m1 (MSt m1 m2 a)
pullBack :: m1 (MSt m1 m2 a) -> m2 a
instance Monad m => MorphControl m (MaybeT m) where
newtype MSt m (MaybeT m) a = MaybeMSt { fromMaybeMSt :: Maybe a }
sink = liftM MaybeMSt . runMaybeT
pullBack = MaybeT . liftM fromMaybeMSt
instance Monad m => MorphControl m (ListT m) where
newtype MSt m (ListT m) a = ListMSt { fromListMSt :: [a] }
sink = liftM ListMSt . runListT
pullBack = ListT . liftM fromListMSt
instance MorphControl IO IO where
newtype MSt IO IO a = ReflIOMSt { fromReflIOMSt :: a }
sink = liftM ReflIOMSt
pullBack = liftM fromReflIOMSt
instance (Monad m) => MorphControl m MU where
newtype MSt m MU a = ProxyMSt ()
sink _ = return (ProxyMSt ())
pullBack _ = Proxy