-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at https://mozilla.org/MPL/2.0/.

{- |
Copyright   :  (c) 2024 Sayo Koyoneda
License     :  MPL-2.0 (see the LICENSE file)
Maintainer  :  ymdfield@outlook.jp
Portability :  portable
-}
module Control.Monad.Hefty.Fail where

import Control.Monad.Hefty (Eff, interpret, liftIO, type (<|), type (~>))
import Data.Effect.Fail (Fail (Fail))

runFailIO :: (IO <| ef) => Eff eh (Fail ': ef) ~> Eff eh ef
runFailIO :: forall (ef :: [EffectF]) (eh :: [EffectH]).
(IO <| ef) =>
Eff eh (Fail : ef) ~> Eff eh ef
runFailIO = (Fail ~> Eff eh ef) -> Eff eh (Fail : ef) ~> Eff eh ef
forall (e :: EffectF) (ef :: [EffectF]) (eh :: [EffectH]).
(e ~> Eff eh ef) -> Eff eh (e : ef) ~> Eff eh ef
interpret \(Fail String
s) -> IO x -> Eff eh ef x
forall a. IO a -> Eff eh ef a
forall (m :: EffectF) a. MonadIO m => IO a -> m a
liftIO (IO x -> Eff eh ef x) -> IO x -> Eff eh ef x
forall a b. (a -> b) -> a -> b
$ String -> IO x
forall a. String -> IO a
forall (m :: EffectF) a. MonadFail m => String -> m a
fail String
s