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]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

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.12 && <5), invariant (>=0.1.0 && <0.6), MonadRandom (>=0.5 && <0.6), mtl (>=2.2 && <2.3), transformers (>=0.5.6 && <0.6) [details]
License AGPL-3.0-only
Copyright 2020 Eamon Olive, Louis Hyde
Author Eamon Olive, Louis Hyde
Maintainer ejolive97@gmail.com
Revised Revision 3 made by LouisH at 2020-03-17T21:25:16Z
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-02-29T18:19:24Z
Distributions
Downloads 603 total (12 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-02-29 [all 2 reports]

Readme for monad-choice-0.1.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.