emgm-0.4: Extensible and Modular Generics for the Masses

Portabilitynon-portable
Stabilityexperimental
Maintainergenerics@haskell.org

Generics.EMGM.Functions.Read

Description

Summary: Generic functions that parse strings to produce values.

The functions in this module involve generically parsing a string and producing a value. They rely on the return type to determine the structure for parsing. Often, this can be determined by the type checker, but you will occasionally need to give an explicit type signature.

The underlying parser is designed to be as similar to deriving Read (as implemented by GHC) as possible. Refer to documentation in Text.Read for details.

Since this library does not have access to the syntax of a data declaration, it relies on ConDescr for information. It is important that ConDescr accurately describe, for each constructor, the name, record labels (in same order as declared) if present, and fixity.

See also Generics.EMGM.Functions.Show.

Synopsis

Documentation

newtype Read a Source

The type of a generic function that takes a constructor-type argument and returns a parser combinator for some type.

Constructors

Read 

Fields

selRead :: ConType -> ReadPrec a
 

Instances

Generic Read 
Rep Read String

Ad-hoc instance for strings

Rep Read ()

Ad-hoc instance for ()

Rep Read a => Rep Read [a]

Ad-hoc instance for lists

(Rep Read a, Rep Read b) => Rep Read (a, b)

Ad-hoc instance for (a,b)

(Rep Read a, Rep Read b, Rep Read c) => Rep Read (a, b, c)

Ad-hoc instance for (a,b,c)

(Rep Read a, Rep Read b, Rep Read c, Rep Read d) => Rep Read (a, b, c, d)

Ad-hoc instance for (a,b,c,d)

(Rep Read a, Rep Read b, Rep Read c, Rep Read d, Rep Read e) => Rep Read (a, b, c, d, e)

Ad-hoc instance for (a,b,c,d,e)

(Rep Read a, Rep Read b, Rep Read c, Rep Read d, Rep Read e, Rep Read f) => Rep Read (a, b, c, d, e, f)

Ad-hoc instance for (a,b,c,d,e,f)

(Rep Read a, Rep Read b, Rep Read c, Rep Read d, Rep Read e, Rep Read f, Rep Read h) => Rep Read (a, b, c, d, e, f, h)

Ad-hoc instance for (a,b,c,d,e,f,h)

readPrec :: Rep Read a => ReadPrec aSource

Generate a ReadPrec parser combinator for the datatype a that handles operator precedence. This uses the library in Text.ParserCombinators.ReadPrec and should be similar to a derived implementation of Text.Read.readPrec.

readPSource

Arguments

:: Rep Read a 
=> Int

Operator precedence of the enclosing context (a number from 0 to 11).

-> ReadP a 

Generate a ReadP parser combinator for the datatype a. This can be used with Text.ParserCombinators.ReadP.

readsPrecSource

Arguments

:: Rep Read a 
=> Int

Operator precedence of the enclosing context (a number from 0 to 11).

-> ReadS a

Equivalent to String -> [(a,String)].

Attempt to parse a value from the front of the string using the given precedence. readsPrec returns a list of (parsed value, remaining string) pairs. If parsing fails, readsPrec returns an empty list.

reads :: Rep Read a => ReadS aSource

A variant of readsPrec with the minimum precedence (0).

read :: Rep Read a => String -> Maybe aSource

A variant of reads that returns Just value on a successful parse. Otherwise, read returns Nothing. Note that a successful parse requires the input to be completely consumed.