module Data.Foldable.Internal(module Data.Foldable.Internal) whereimport qualified Prelude()import Control.Applicativeimport Control.Monadimport Data.Boolimport Data.Functionimport Data.Functorimport Data.Maybe_Typeimport Data.Monoid.Internal hiding (Max(..), Min(..))import Data.Listimport Data.Ordimport {-# SOURCE #-} Data.Typeablenewtype Max a = Max { getMax :: Maybe a }newtype Min a = Min { getMin :: Maybe a }instance forall a . Ord a => Semigroup (Max a) where m <> Max Nothing = m Max Nothing <> n = n (Max m@(Just x)) <> (Max n@(Just y)) | x >= y = Max m | otherwise = Max ninstance forall a . Ord a => Monoid (Max a) where mempty = Max Nothing mconcat = foldl' (<>) memptyinstance forall a . Ord a => Semigroup (Min a) where m <> Min Nothing = m Min Nothing <> n = n (Min m@(Just x)) <> (Min n@(Just y)) | x <= y = Min m | otherwise = Min ninstance forall a . Ord a => Monoid (Min a) where mempty = Min Nothing mconcat = foldl' (<>) memptynewtype StateL s a = StateL { runStateL :: s -> (s, a) }instance Functor (StateL s) where fmap f (StateL k) = StateL $ \ s -> let (s', v) = k s in (s', f v)instance Applicative (StateL s) where pure x = StateL (\ s -> (s, x)) StateL kf <*> StateL kv = StateL $ \ s -> let (s', f) = kf s (s'', v) = kv s' in (s'', f v)newtype StateR s a = StateR { runStateR :: s -> (s, a) }instance Functor (StateR s) where fmap f (StateR k) = StateR $ \ s -> let (s', v) = k s in (s', f v)instance Applicative (StateR s) where pure x = StateR (\ s -> (s, x)) StateR kf <*> StateR kv = StateR $ \ s -> let (s', v) = kv s (s'', f) = kf s' in (s'', f v)newtype StateT s m a = StateT { runStateT :: s -> m (s, a) }instance Monad m => Functor (StateT s m) where fmap = liftMinstance Monad m => Applicative (StateT s m) where pure a = StateT $ \ s -> return (s, a) StateT mf <*> StateT mx = StateT $ \ s -> do (s', f) <- mf s (s'', x) <- mx s' return (s'', f x)instance (Monad m) => Monad (StateT s m) where m >>= k = StateT $ \ s -> do (s', a) <- runStateT m s runStateT (k a) s'