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

{-# OPTIONS_GHC -Wno-orphans #-}

module Data.Monoid.Extra where

import Control.Monad.State (MonadState(..))
import Data.Monoid (Ap(Ap))

instance (MonadState s m) => MonadState s (Ap m) where
  get :: Ap m s
get = m s -> Ap m s
forall k (f :: k -> Type) (a :: k). f a -> Ap f a
Ap m s
forall s (m :: Type -> Type). MonadState s m => m s
get
  put :: s -> Ap m ()
put = m () -> Ap m ()
forall k (f :: k -> Type) (a :: k). f a -> Ap f a
Ap (m () -> Ap m ()) -> (s -> m ()) -> s -> Ap m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> m ()
forall s (m :: Type -> Type). MonadState s m => s -> m ()
put
  state :: (s -> (a, s)) -> Ap m a
state = m a -> Ap m a
forall k (f :: k -> Type) (a :: k). f a -> Ap f a
Ap (m a -> Ap m a)
-> ((s -> (a, s)) -> m a) -> (s -> (a, s)) -> Ap m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (s -> (a, s)) -> m a
forall s (m :: Type -> Type) a.
MonadState s m =>
(s -> (a, s)) -> m a
state