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

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

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]

Properties

Versions 0.1.0.0, 0.2.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:49:24Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


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.