mirror of
https://github.com/polysemy-research/polysemy.git
synced 2024-11-30 07:13:55 +03:00
26a6d2e474
* Add Fail effect
* Add inlining to Fail interpreters, make Fail newtype
* Hide visibility of Polysemy.Fixpoint.bomb, fix changelog
* Revert "Hide visibility of Polysemy.Fixpoint.bomb, fix changelog"
This reverts commit 5b043ed215
.
* Move Polysemy.Internal.Fail to Polysemy.Fail.Type. Fixed inconsistency in docs
26 lines
717 B
Haskell
26 lines
717 B
Haskell
module FailSpec where
|
|
|
|
import Polysemy
|
|
import Polysemy.Fail
|
|
import Polysemy.NonDet
|
|
import Test.Hspec
|
|
import Control.Applicative
|
|
|
|
semFail :: Member Fail r => Maybe Bool -> Sem r Bool
|
|
semFail mb = do
|
|
Just b <- pure mb
|
|
pure b
|
|
|
|
runAlt :: Alternative f => Sem '[Fail, NonDet] a -> f a
|
|
runAlt = run . runNonDet . failToNonDet
|
|
|
|
spec :: Spec
|
|
spec = parallel $ do
|
|
describe "MonadFail instance with failToNonDet" $ do
|
|
it "should call empty via fail" $ do
|
|
runAlt (semFail Nothing) `shouldBe` Nothing
|
|
runAlt (semFail Nothing) `shouldBe` []
|
|
it "should work fine for non-failing patterns" $ do
|
|
runAlt (semFail $ Just True) `shouldBe` Just True
|
|
runAlt (semFail $ Just False) `shouldBe` [False]
|