| Copyright | (c) Eamon Olive 2020 (c) Louis Hyde 2020 | 
|---|---|
| License | AGPL-3 | 
| Maintainer | ejolive97@gmail.com | 
| Stability | experimental | 
| Safe Haskell | Safe | 
| Language | Haskell2010 | 
Control.Monad.Class.Choice
Description
Synopsis
- class Monad m => MonadChoice f m where- choose :: f a -> m a
 
- chooseM :: MonadChoice f m => f (m a) -> m a
Documentation
class Monad m => MonadChoice f m where Source #
A monad with a series of dependent choices.
 It is usually desirable to have f be a Foldable so that a selection can be made from it.
As an example here is a simple berry name generator:
berry :: MonadChoice NonEmpty m => m String berry = do berryColor <- choose $ "red" :| ["blue", "orange", "yellow", "black"] berryFlavor <- choose $ "sweet" :| ["sour", "bitter"] (++ "berry") <$> choose ( berryColor :| [berryFlavor, berryColor ++ "-" ++ berryFlavor] )
Since this has a polymorphic type this could be used for a variety of purposes.
Instances
chooseM :: MonadChoice f m => f (m a) -> m a Source #
Makes a selection where options are themselves selections.