{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TupleSections #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Effect.Fail.Passthrough where

import Effect
import Effect.Fail

-- | A "passthough" instance for 'WriterEffect's: Modifications are applied
-- in all nested positions of 'Listen' and 'Pass', but don't actually change the
-- semantics of any 'WriterEffect'.
instance (MonadFail m) => InterpretEffectStateful x m MonadFailEffect where
  interpretEffectStateful :: forall (ops :: [Effect]) x a.
(forall b y. x y -> AST ops b -> m (b, x y))
-> x x -> MonadFailEffect (AST ops) a -> m (a, x x)
interpretEffectStateful forall b y. x y -> AST ops b -> m (b, x y)
_ x x
x (Fail String
msg) = (,x x
x) (a -> (a, x x)) -> m a -> m (a, x x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m a
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
msg