@hackage monad-choice0.2.0.0
Monad, monad transformer, and typeclass representing choices.
Categories
License
AGPL-3.0-only
Maintainer
ejolive97@gmail.com
Links
Versions
Installation
Dependencies (7)
- MonadRandom >=0.5 && <0.6
- base >=4.9 && <5
- contravariant >=1.4 && <1.6
- invariant >=0.4 && <0.6
- mtl >=2.2.1 && <2.3
- primitive >=0.6.1 && <0.8 Show all…
Dependents (0)
The monad-choice package
This package provides a multipurpose monad transformer (and associated monad and class), to represent the idea of a result depending on the outcomes of a series of choices.
Example
The following is a simple use of MonadChoice for creating the name of a berry.
{-# Language FlexibleContexts #-}
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] )
This can be used with MonadRandom to create a random berry, used with Gen to create berries for unit tests, or with user input as the structure for a menu where the user selects a berry.