{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Control.Carrier.Trace.Ignoring
(
runTrace
, TraceC(..)
, module Control.Effect.Trace
) where
import Control.Algebra
import Control.Applicative (Alternative)
import Control.Effect.Trace
import Control.Monad (MonadPlus)
import Control.Monad.Fail as Fail
import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
runTrace :: TraceC m a -> m a
runTrace (TraceC m) = m
{-# INLINE runTrace #-}
newtype TraceC m a = TraceC (m a)
deriving (Alternative, Applicative, Functor, Monad, Fail.MonadFail, MonadFix, MonadIO, MonadPlus)
instance MonadTrans TraceC where
lift = TraceC
{-# INLINE lift #-}
instance Algebra sig m => Algebra (Trace :+: sig) (TraceC m) where
alg hdl = \case
L (Trace _) -> pure
R other -> TraceC . alg (runTrace . hdl) other
{-# INLINE alg #-}