Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor Fail
Browse files Browse the repository at this point in the history
janmasrovira committed Nov 20, 2024
1 parent a889cb6 commit f8fd9f4
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Juvix/Data/Effect/Fail.hs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
-- | An effect similar to Polysemy Fail but without an error message
module Juvix.Data.Effect.Fail where
module Juvix.Data.Effect.Fail
( module Juvix.Data.Effect.Fail,
module Effectful.Fail,
)
where

import Control.Exception qualified as X
import Control.Monad.Fail qualified as Fail
import Effectful.Fail (Fail)
import Effectful.Fail qualified as Fail
import Juvix.Prelude.Base

data Fail :: Effect where
Fail :: Fail m a

makeSem ''Fail
fail :: (Member Fail r) => Sem r a
fail = Fail.fail "fail"

-- | Run a 'Fail' effect purely.
runFail ::
Sem (Fail ': r) a ->
Sem r (Maybe a)
runFail = fmap (^? _Right) . reinterpret (runError @()) (\Fail -> throw ())
runFail = fmap (^? _Right) . reinterpret (runError @()) (\Fail.Fail {} -> throw ())
{-# INLINE runFail #-}

-- | Run a 'Fail' effect purely with a default value.

0 comments on commit f8fd9f4

Please sign in to comment.