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

{-# OPTIONS_GHC -Wno-orphans #-}

module Data.Semigroup.Monad.Extra
  (module Data.Semigroup.Monad
  )
where

import Control.Monad.Fix
import Control.Monad.State
import Data.Semigroup.Monad

instance MonadFix f => MonadFix (Mon f) where
  mfix :: (a -> Mon f a) -> Mon f a
mfix a -> Mon f a
f = f a -> Mon f a
forall (f :: Type -> Type) m. f m -> Mon f m
Mon ((a -> f a) -> f a
forall (m :: Type -> Type) a. MonadFix m => (a -> m a) -> m a
mfix (Mon f a -> f a
forall (f :: Type -> Type) m. Mon f m -> f m
getMon (Mon f a -> f a) -> (a -> Mon f a) -> a -> f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Mon f a
f))

instance MonadState s m => MonadState s (Mon m) where
  get :: Mon m s
get = m s -> Mon m s
forall (f :: Type -> Type) m. f m -> Mon f m
Mon m s
forall s (m :: Type -> Type). MonadState s m => m s
get
  put :: s -> Mon m ()
put = m () -> Mon m ()
forall (f :: Type -> Type) m. f m -> Mon f m
Mon (m () -> Mon m ()) -> (s -> m ()) -> s -> Mon 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)) -> Mon m a
state = m a -> Mon m a
forall (f :: Type -> Type) m. f m -> Mon f m
Mon (m a -> Mon m a)
-> ((s -> (a, s)) -> m a) -> (s -> (a, s)) -> Mon 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