TV-0.5.0: Tangible Values -- composable interfaces

PortabilityRank2Types
Stabilityexperimental
Maintainerconal@conal.net
Safe HaskellNone

Interface.TV.Common

Contents

Description

Some common interaction vocabulary

Synopsis

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

Instances

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.

getReadF :: (CommonIns src, Functor src, Show a, Read a) => a -> src aSource

class CommonOuts snk whereSource

This class captures some useful operations available in some arrows and allows definition of some "Common" Inputs, Outputs, and TVs.

Methods

putString :: snk StringSource

Output a string

putShow :: Show a => snk aSource

Shows based outout. Define as putShowC when snk is a ContraFunctor

putBool :: snk BoolSource

Output a bool

Instances

putShowC :: (CommonOuts snk, ContraFunctor snk, Show a) => snk aSource

type CInput a = forall src. CommonIns src => Input src aSource

Inputs that work over all CommonInsOuts typecons.

type CInputI a = a -> CInput aSource

CInput with initial value

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

stringIn :: CInputI StringSource

String input with default

boolIn :: CInputI BoolSource

Bool input with default

readIn :: (Read a, Show a) => CInputI aSource

Input a readable value. Use default when read fails.

Outputs

stringOut :: COutput StringSource

Output a string

boolOut :: COutput BoolSource

Output a bool

showOut :: Show a => COutput aSource

Output a showable value

interactLine :: String -> COutput (String -> String)Source

Output version of interact. Well, not quite, since the IO version uses getLine instead of getContents. See also interactOut

readShowSource

Arguments

:: (Read a, Show b, CommonIns src, CommonOuts snk, Functor src, ContraFunctor snk) 
=> Output src snk (String -> String)

base output

-> a

default, when read fails

-> Output src snk (a -> b) 

Handy Read+Show wrapper

interactLineRSSource

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