monad-choice: Monad, monad transformer, and typeclass representing choices.

[ agpl, control, library ] [ Propose Tags ]

The Monad Choice library contains monads, monad transformers, and a typeclass representing a sequence of choices of objects of arbitrary types where future choices can depend on previous ones.

[Skip to Readme]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS],
Change log
Dependencies base (>=4.9 && <5), contravariant (>=1.4 && <1.6), invariant (>=0.4 && <0.6), MonadRandom (>=0.5 && <0.6), mtl (>=2.2.1 && <2.3), primitive (>=0.6.1 && <0.8), transformers (>=0.5.3 && <0.6) [details]
License AGPL-3.0-only
Copyright 2020 Eamon Olive, Louis Hyde
Author Eamon Olive, Louis Hyde
Category Control
Home page
Source repo head: git clone
Uploaded by LouisH at 2020-03-27T03:51:32Z
Downloads 639 total (8 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-03-27 [all 1 reports]

Readme for monad-choice-

[back to package description]

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.


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.