| Haskell Hierarchical Libraries (base package) | Contents | Index

Text.Read

Portability | non-portable (uses Text.ParserCombinators.ReadP)
Stability | provisional
Maintainer | libraries@haskell.org

Contents

The `Read` class
Haskell 98 functions
New parsing functions

Description
The Text.Read library is the canonical library to import for `Read`-class facilities. For GHC only, it offers an extended and much improved `Read` class, which constitutes a proposed alternative to the Haskell 98 `Read`. In particular, writing parsers is easier, and the parsers are much more efficient.
Synopsis

class Read a where

readsPrec :: Int -> ReadS a
readList :: ReadS [a]
readPrec :: ReadPrec a
readListPrec :: ReadPrec [a]

type ReadS a = String -> [(a, String)]
reads :: Read a => ReadS a
read :: Read a => String -> a
readParen :: Bool -> ReadS a -> ReadS a
lex :: ReadS String
module Text.ParserCombinators.ReadPrec

data Lexeme

= Char Char
| String String
| Punc String
| Ident String
| Symbol String
| Int Integer
| Rat Rational
| EOF

lexP :: ReadPrec Lexeme
readListDefault :: Read a => ReadS [a]
readListPrecDefault :: Read a => ReadPrec [a]

The `Read` class
class Read a where

Methods

readsPrec :: Int -> ReadS a
readList :: ReadS [a]
readPrec :: ReadPrec a
Proposed replacement for `readsPrec` using new-style parsers (GHC only).
readListPrec :: ReadPrec [a]
Proposed replacement for `readList` using new-style parsers (GHC only).

Instances

(RealFloat a, Read a) => Read (Complex a)
Read CChar
Read CSChar
Read CUChar
Read CShort
Read CUShort
Read CInt
Read CUInt
Read CLong
Read CULong
Read CLLong
Read CULLong
Read CFloat
Read CDouble
Read CLDouble
Read CPtrdiff
Read CSize
Read CWchar
Read CSigAtomic
Read CClock
Read CTime
Read SeekMode
Read BufferMode
Read ExitCode
Read IOMode
Read Int8
Read Int16
Read Int32
Read Int64
Read Char
Read Bool
Read Ordering
Read a => Read (Maybe a)
(Read a, Read b) => Read (Either a b)
Read a => Read [a]
(Ix a, Read a, Read b) => Read (Array a b)
Read Lexeme
Read Int
Read Integer
Read Float
Read Double
(Integral a, Read a) => Read (Ratio a)
Read ()
(Read a, Read b) => Read (a, b)
(Read a, Read b, Read c) => Read (a, b, c)
(Read a, Read b, Read c, Read d) => Read (a, b, c, d)
(Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e)
Read Word
Read Word8
Read Word16
Read Word32
Read Word64
Read Permissions
Read CDev
Read CIno
Read CMode
Read COff
Read CPid
Read CSsize
Read CGid
Read CNlink
Read CUid
Read CCc
Read CSpeed
Read CTcflag
Read Fd
Read StdGen
Read Month
Read Day
Read CalendarTime
Read TimeDiff

type ReadS a = String -> [(a, String)]
A parser for a type `a`, represented as a function that takes a `String` and returns a list of possible parses `(a,`String`)` pairs.
Haskell 98 functions
reads :: Read a => ReadS a
read :: Read a => String -> a
readParen :: Bool -> ReadS a -> ReadS a
lex :: ReadS String
New parsing functions
module Text.ParserCombinators.ReadPrec
data Lexeme

Constructors

Char Char |
String String |
Punc String |
Ident String |
Symbol String |
Int Integer |
Rat Rational |
EOF |

Instances

Read Lexeme
Eq Lexeme
Show Lexeme

lexP :: ReadPrec Lexeme
Parse a single lexeme
readListDefault :: Read a => ReadS [a]
Use this to define the `readList` method, if you don't want a special case (GHC only; for other systems the default suffices).
readListPrecDefault :: Read a => ReadPrec [a]
Use this to define the `readListPrec` method, if you don't want a special case (GHC only).
Produced by Haddock version 0.6