emgm-0.3.1: Extensible and Modular Generics for the MassesSource codeContentsIndex
Generics.EMGM.Functions.Read
Portabilitynon-portable
Stabilityexperimental
Maintainergenerics@haskell.org
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
newtype Read a = Read {
selRead :: ConType -> ReadPrec a
}
readPrec :: Rep Read a => ReadPrec a
readP :: Rep Read a => Int -> ReadP a
readsPrec :: Rep Read a => Int -> ReadS a
reads :: Rep Read a => ReadS a
read :: Rep Read a => String -> Maybe a
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
selRead :: ConType -> ReadPrec a
show/hide Instances
Generic Read
Rep Read String
Rep Read ()
Rep Read a => Rep Read ([] a)
(Rep Read a, Rep Read b) => Rep Read ((,) a b)
(Rep Read a, Rep Read b, Rep Read c) => Rep Read ((,,) a b c)
(Rep Read a, Rep Read b, Rep Read c, Rep Read d) => Rep Read ((,,,) 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)
(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)
(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)
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
:: Rep Read a
=> IntOperator 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
:: Rep Read a
=> IntOperator precedence of the enclosing context (a number from 0 to 11).
-> ReadS aEquivalent 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.
Produced by Haddock version 2.4.2