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

[ agpl, control, library ] [ Propose Tags ] [ Report a vulnerability ]

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]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.2.0.0
Change log CHANGELOG.md
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
Maintainer ejolive97@gmail.com
Category Control
Home page https://gitlab.com/e-neighborhood-watch/monad-choice#readme
Source repo head: git clone https://gitlab.com/e-neighborhood-watch/monad-choice.git
Uploaded by LouisH at 2020-03-27T03:51:32Z
Distributions
Downloads 672 total (5 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-0.2.0.0

[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.

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.