| Portability | Rank2Types |
|---|---|
| Stability | experimental |
| Maintainer | conal@conal.net |
Interface.TV.Common
Contents
Description
Some common interaction vocabulary
- class CommonIns src where
- readD :: Read a => a -> String -> a
- getReadF :: (CommonIns src, Functor src, Show a, Read a) => a -> src a
- class CommonOuts snk where
- putShowC :: (CommonOuts snk, Cofunctor snk, Show a) => snk a
- type CInput a = forall src. CommonIns src => Input src a
- type CInputI a = a -> CInput a
- type COutput a = forall src snk. (CommonIns src, CommonOuts snk) => Output src snk a
- type CTV a = forall src snk. (CommonIns src, CommonOuts snk) => TV src snk a
- stringIn :: CInputI String
- boolIn :: CInputI Bool
- readIn :: (Read a, Show a) => CInputI a
- stringOut :: COutput String
- boolOut :: COutput Bool
- showOut :: Show a => COutput a
- interactLine :: String -> COutput (String -> String)
- readShow :: (Read a, Show b, CommonIns src, CommonOuts snk, Functor src, Cofunctor snk) => Output src snk (String -> String) -> a -> Output src snk (a -> b)
- interactLineRS :: (Read a, Show a, Show b, CommonIns src, CommonOuts snk) => a -> Output src snk (a -> b)
Type class
class CommonIns src whereSource
This class captures some useful operations available in some input
types, and allows definition of some "Common" Inputs
Methods
getString :: String -> src StringSource
Input a string (with default)
getRead :: (Show a, Read a) => a -> src aSource
Read-based input. Initial value is also used as a default for
failed parse. Define as getReadF when src is a Functor.
Requires Show as well as Read, for displaying the initial value.
getBool :: Bool -> src BoolSource
Input a bool
readD :: Read a => a -> String -> aSource
Read with default value. If the input doesn't parse as a value of the expected type, or it's ambiguous, yield the default value.
class CommonOuts snk whereSource
This class captures some useful operations available in some arrows
and allows definition of some "Common" Inputs, Outputs, and
TVs.
Instances
putShowC :: (CommonOuts snk, Cofunctor snk, Show a) => snk aSource
type CInput a = forall src. CommonIns src => Input src aSource
Inputs that work over all CommonInsOuts typecons.
type COutput a = forall src snk. (CommonIns src, CommonOuts snk) => Output src snk aSource
Outputs that work over all CommonOuts typecons.
type CTV a = forall src snk. (CommonIns src, CommonOuts snk) => TV src snk aSource
Convenient type synonym for TVs that work over all CommonInsOuts typecons.
Inputs
Outputs
interactLine :: String -> COutput (String -> String)Source
Output version of interact. Well, not quite, since the IO
version uses getLine instead of getContents. See also
Interface.TV.interactOut
Arguments
| :: (Read a, Show b, CommonIns src, CommonOuts snk, Functor src, Cofunctor snk) | |
| => Output src snk (String -> String) | base output |
| -> a | default, when read fails |
| -> Output src snk (a -> b) |
Handy Read+Show wrapper
Arguments
| :: (Read a, Show a, Show b, CommonIns src, CommonOuts snk) | |
| => a | default, if read fails |
| -> Output src snk (a -> b) |
Read+Show of interactLine