- newtype Wizard backend a = Wizard (MaybeT (Free backend) a)
- type PromptString = String
- run :: (Functor f, Monad b, Run b f) => Wizard f a -> b (Maybe a)
- class (Functor sub, Functor sup) => sub :<: sup
- data (f :+: g) w
- data Line w
- line :: Line :<: b => PromptString -> Wizard b String
- data LinePrewritten w
- linePrewritten :: LinePrewritten :<: b => PromptString -> String -> String -> Wizard b String
- data Password w
- password :: Password :<: b => PromptString -> Maybe Char -> Wizard b String
- data Character w
- character :: Character :<: b => PromptString -> Wizard b Char
- data Output w
- output :: Output :<: b => String -> Wizard b ()
- data OutputLn w
- outputLn :: OutputLn :<: b => String -> Wizard b ()
- data ArbitraryIO w
- retry :: Functor b => Wizard b a -> Wizard b a
- retryMsg :: OutputLn :<: b => String -> Wizard b a -> Wizard b a
- defaultTo :: Functor b => Wizard b a -> a -> Wizard b a
- parser :: Functor b => (a -> Maybe c) -> Wizard b a -> Wizard b c
- validator :: Functor b => (a -> Bool) -> Wizard b a -> Wizard b a
- nonEmpty :: Functor b => Wizard b [a] -> Wizard b [a]
- inRange :: (Ord a, Functor b) => (a, a) -> Wizard b a -> Wizard b a
- parseRead :: (Read a, Functor b) => Wizard b String -> Wizard b a
- liftMaybe :: Functor b => Maybe a -> Wizard b a
- ensure :: (a -> Bool) -> a -> Maybe a
- readP :: Read a => String -> Maybe a
Wizard b a is a conversation with the user via back-end
b that will result in a data type
a, or may fail.
Wizard is made up of one or more "primitives" (see below), composed using the
Alternative instances. The
Alternative instance is, as you might expect, a maybe-style cascade.
If the first wizard fails, the next one is tried.
mzero can be used to induce failure directly.
Wizard constructor is exported here for use when developing backends, but it is better for end-users to
simply pretend that
Wizard is an opaque data type. Don't depend on this unless you have no other choice.
Wizards are, internally, just a maybe transformer over a free monad built from some coproduct of functors,
each of which is a primitive action.
Run a wizard using some back-end.
Subsumption of two functors. You shouldn't define any of your own instances of this when writing back-ends, rely only on GeneralizedNewtypeDeriving.
|Functor f => f :<: f|
|ArbitraryIO :<: Haskeline|
|ArbitraryIO :<: BasicIO|
|Password :<: Haskeline|
|LinePrewritten :<: Haskeline|
|Character :<: Haskeline|
|Character :<: BasicIO|
|Character :<: Pure|
|Line :<: Haskeline|
|Line :<: BasicIO|
|Line :<: Pure|
|OutputLn :<: Haskeline|
|OutputLn :<: BasicIO|
|OutputLn :<: Pure|
|Output :<: Haskeline|
|Output :<: BasicIO|
|Output :<: Pure|
|WithSettings :<: Haskeline|
|(Functor f, Functor g, Functor h, :<: f g) => f :<: (:+: h g)|
|(Functor f, Functor g) => f :<: (:+: f g)|
Coproduct of two functors
Primitives are the basic building blocks for
wizards. Use these functions to produce wizards that
ask for input from the user, or output information.
Read one line of input from the user. Cannot fail (but may throw exceptions, depending on the backend).
|:: LinePrewritten :<: b|
Text to the left of the cursor
Text to the right of the cursor
|-> Wizard b String|
Read one line of input, with some default text already present, before and/or after the editing cursor.
Read one line of password input, with an optional mask character.
Read a single character only from input. Cannot fail (but may throw exceptions, depending on the backend).
Output a string followed by a newline. Does not fail.
Modifiers change the behaviour of existing wizards.
Retry produces a wizard that will retry the entire conversation again if it fails.
It is simply
retry x = x <|> retry x.
retry, except an error message can be specified.
x `defaultTo` y will return
x fails, e.g
parseRead line `defaultTo` 0.
validator p causes a wizard to fail if the output value does not satisfy the predicate
validator (not . null), makes a wizard fail if it gets an empty string.
Makes a wizard fail if it gets an ordered quantity outside of the given range.
parser readP. Attaches a simple
read parser to a
Translate a maybe value into wizard success/failure.