Copyright | (c) 2024 Sayo Koyoneda |
---|---|
License | MPL-2.0 (see the LICENSE file) |
Maintainer | ymdfield@outlook.jp |
Safe Haskell | None |
Language | GHC2021 |
Control.Monad.Hefty.NonDet
Description
Interpreters for the non-determinism effects.
Synopsis
- choice :: forall (ef :: [EffectF]) a (eh :: [EffectH]). (Choose <| ef, Empty <| ef) => [a] -> Eff eh ef a
- runNonDet :: forall f (ef :: [Type -> Type]) a. Alternative f => Eff ('[] :: [EffectH]) (Choose ': (Empty ': ef)) a -> Eff ('[] :: [EffectH]) ef (f a)
- runNonDetMonoid :: forall ans (ef :: [EffectF]) a. Monoid ans => (a -> Eff ('[] :: [EffectH]) ef ans) -> Eff ('[] :: [EffectH]) (Choose ': (Empty ': ef)) a -> Eff ('[] :: [EffectH]) ef ans
- runChoose :: forall f (ef :: [Type -> Type]) a. Alternative f => Eff ('[] :: [EffectH]) (Choose ': ef) a -> Eff ('[] :: [EffectH]) ef (f a)
- runChooseMonoid :: forall ans (ef :: [EffectF]) a. Semigroup ans => (a -> Eff ('[] :: [EffectH]) ef ans) -> Eff ('[] :: [EffectH]) (Choose ': ef) a -> Eff ('[] :: [EffectH]) ef ans
- runEmpty :: forall a (ef :: [Type -> Type]). Eff ('[] :: [EffectH]) (Empty ': ef) a -> Eff ('[] :: [EffectH]) ef (Maybe a)
- runChooseH :: forall (ef :: [EffectF]) (eh :: [(Type -> Type) -> Type -> Type]). Choose <| ef => Eff (ChooseH ': eh) ef ~> Eff eh ef
- branch :: forall (ef :: [EffectF]) (eh :: [EffectH]) a. Choose <| ef => Eff eh ef a -> Eff eh ef a -> Eff eh ef a
- choiceH :: forall (eh :: [EffectH]) (ef :: [EffectF]) a. (ChooseH <<| eh, Empty <| ef) => [a] -> Eff eh ef a
- runNonDetIO :: forall (eh :: [EffectH]) (ef :: [EffectF]) a. (UnliftIO <<| eh, IO <| ef) => Eff (ChooseH ': eh) (Empty ': ef) a -> Eff eh ef (Either SomeException a)
- data EmptyException = EmptyException
- module Data.Effect.NonDet
Documentation
choice :: forall (ef :: [EffectF]) a (eh :: [EffectH]). (Choose <| ef, Empty <| ef) => [a] -> Eff eh ef a Source #
Selects one element from the list nondeterministically, branching the control as many times as the number of elements.
runNonDet :: forall f (ef :: [Type -> Type]) a. Alternative f => Eff ('[] :: [EffectH]) (Choose ': (Empty ': ef)) a -> Eff ('[] :: [EffectH]) ef (f a) Source #
NonDet effects handler for alternative answer type.
runNonDetMonoid :: forall ans (ef :: [EffectF]) a. Monoid ans => (a -> Eff ('[] :: [EffectH]) ef ans) -> Eff ('[] :: [EffectH]) (Choose ': (Empty ': ef)) a -> Eff ('[] :: [EffectH]) ef ans Source #
NonDet effects handler for monoidal answer type.
runChoose :: forall f (ef :: [Type -> Type]) a. Alternative f => Eff ('[] :: [EffectH]) (Choose ': ef) a -> Eff ('[] :: [EffectH]) ef (f a) Source #
Choose
effect handler for alternative answer type.
runChooseMonoid :: forall ans (ef :: [EffectF]) a. Semigroup ans => (a -> Eff ('[] :: [EffectH]) ef ans) -> Eff ('[] :: [EffectH]) (Choose ': ef) a -> Eff ('[] :: [EffectH]) ef ans Source #
Choose
effect handler for monoidal answer type.
runEmpty :: forall a (ef :: [Type -> Type]). Eff ('[] :: [EffectH]) (Empty ': ef) a -> Eff ('[] :: [EffectH]) ef (Maybe a) Source #
Empty
effect handler.
runChooseH :: forall (ef :: [EffectF]) (eh :: [(Type -> Type) -> Type -> Type]). Choose <| ef => Eff (ChooseH ': eh) ef ~> Eff eh ef Source #
ChooseH
effect elaborator.
Convert a higher-order effect of the form
chooseH :: m a -> m a -> m a
into a first-order effect of the form:
choose :: m Bool
branch :: forall (ef :: [EffectF]) (eh :: [EffectH]) a. Choose <| ef => Eff eh ef a -> Eff eh ef a -> Eff eh ef a infixl 3 Source #
Faster than <|>
.
choiceH :: forall (eh :: [EffectH]) (ef :: [EffectF]) a. (ChooseH <<| eh, Empty <| ef) => [a] -> Eff eh ef a Source #
Selects one element from the list nondeterministically, branching the control as many times as the number of elements. Uses ChooseH
.
runNonDetIO :: forall (eh :: [EffectH]) (ef :: [EffectF]) a. (UnliftIO <<| eh, IO <| ef) => Eff (ChooseH ': eh) (Empty ': ef) a -> Eff eh ef (Either SomeException a) Source #
Interprets the NonDet effects using IO-level exceptions.
When empty
occurs, an EmptyException
is thrown, and unless all branches from
chooseH
fail due to IO-level exceptions, only the leftmost result is returned
as the final result.
data EmptyException Source #
Exception thrown when empty
occurs in runNonDetIO
.
Constructors
EmptyException |
Instances
Exception EmptyException Source # | |
Defined in Control.Monad.Hefty.NonDet Methods toException :: EmptyException -> SomeException # | |
Show EmptyException Source # | |
Defined in Control.Monad.Hefty.NonDet Methods showsPrec :: Int -> EmptyException -> ShowS # show :: EmptyException -> String # showList :: [EmptyException] -> ShowS # |
module Data.Effect.NonDet