prompt-0.1.0.0: Monad (and transformer) for deferred-effect pure prompt-response queries

Copyright(c) Justin Le 2015
LicenseMIT
Maintainerjustin@jle.im
Stabilityunstable
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Control.Monad.Prompt.Class

Description

Provides a typeclass for Applicative and Monad types that give you the ability to, at any time, "prompt" with an a and get a b in response. The power of this instance is that each type gets to define its own way to deliver a response.

This library provides instances for PromptT from Control.Monad.Prompt and the monad transformers in transformers and mtl. Feel free to create your own instances too.

data Interactive a = Interactive ((String -> String) -> a)

-- at any time, ask with a string to get a string
instance MonadPrompt String String Interactive where
    prompt str = Interactive $ f -> f str

Synopsis

Documentation

class Applicative m => MonadPrompt a b m | m -> a b where Source

An Applicative (and possibly Monad) where you can, at any time, "prompt" with an a and receive a b in response.

Instances include PromptT and any transformers monad transformer over another MonadPrompt.

Minimal complete definition

prompt | prompts

Methods

prompt Source

Arguments

:: a

prompting value

-> m b 

Prompt with an a for a b in the context of the type.

prompts Source

Arguments

:: (b -> c)

mapping function

-> a

prompting value

-> m c 

Prompt with an a for a b in the context of the type, and apply the given function to receive a c.

Instances

(Monad m, MonadPrompt a b m) => MonadPrompt a b (MaybeT m) Source 
(Monad m, MonadPrompt a b m, Monoid w) => MonadPrompt a b (WriterT w m) Source 
(Monad m, MonadPrompt a b m, Monoid w) => MonadPrompt a b (WriterT w m) Source 
(Monad m, MonadPrompt a b m) => MonadPrompt a b (StateT s m) Source 
(Monad m, MonadPrompt a b m) => MonadPrompt a b (StateT s m) Source 
(Monad m, MonadPrompt a b m, Error e) => MonadPrompt a b (ErrorT e m) Source 
(Monad m, MonadPrompt a b m) => MonadPrompt a b (ExceptT e m) Source 
(Monad m, MonadPrompt a b m) => MonadPrompt a b (ReaderT r m) Source 
Applicative t => MonadPrompt a b (PromptT a b t) Source 
(Monad m, MonadPrompt a b m, Monoid w) => MonadPrompt a b (RWST r w s m) Source 
(Monad m, MonadPrompt a b m, Monoid w) => MonadPrompt a b (RWST r w s m) Source 

prompt' :: MonadPrompt a b m => a -> m b Source

A version of prompt strict on its prompting value.

prompts' :: MonadPrompt a b m => (b -> c) -> a -> m c Source

A version of prompts strict on its prompting value.