Data.Textual

data-textual-0.3.0.2: Human-friendly textual representations.

Safe Haskell | None
Language | Haskell2010

Data.Textual

Contents

- Printing
- Parsing
  - Built-in parser

Description

Working with human-friendly (as opposed to the compiler-friendly `Show` and `Read`) textual representations.

Synopsis

- class Printable α where
- maybePrint :: (Printer p, Printable α) => Maybe α -> p
- toString :: Printable α => α -> String
- toText :: Printable α => α -> Text
- toLazyText :: Printable α => α -> Text
- toAscii :: Printable α => α -> ByteString
- toLazyAscii :: Printable α => α -> ByteString
- toUtf8 :: Printable α => α -> ByteString
- toLazyUtf8 :: Printable α => α -> ByteString
- class Printable α => Textual α where
- data Parsed α
  - = Parsed α
  - | Malformed [String] String
- isParsed :: Parsed α -> Bool
- isMalformed :: Parsed α -> Bool
- maybeParsed :: Parsed α -> Maybe α
- builtInParser :: (forall μ. (Monad μ, CharParsing μ) => μ α) -> String -> Parsed α
- parseString :: Textual α => String -> Parsed α
- parseStringAs :: Textual α => p α -> String -> Parsed α
- parseText :: Textual α => Text -> Parsed α
- parseTextAs :: Textual α => p α -> Text -> Parsed α
- parseLazyText :: Textual α => Text -> Parsed α
- parseLazyTextAs :: Textual α => p α -> Text -> Parsed α
- parseAscii :: Textual α => ByteString -> Parsed α
- parseAsciiAs :: Textual α => p α -> ByteString -> Parsed α
- parseLazyAscii :: Textual α => ByteString -> Parsed α
- parseLazyAsciiAs :: Textual α => ByteString -> Parsed α
- parseUtf8 :: Textual α => ByteString -> Parsed α
- parseUtf8As :: Textual α => p α -> ByteString -> Parsed α
- parseLazyUtf8 :: Textual α => ByteString -> Parsed α
- parseLazyUtf8As :: Textual α => p α -> ByteString -> Parsed α
- fromString :: Textual α => String -> Maybe α
- fromStringAs :: Textual α => p α -> String -> Maybe α
- fromText :: Textual α => Text -> Maybe α
- fromTextAs :: Textual α => p α -> Text -> Maybe α
- fromLazyText :: Textual α => Text -> Maybe α
- fromLazyTextAs :: Textual α => p α -> Text -> Maybe α
- fromAscii :: Textual α => ByteString -> Maybe α
- fromAsciiAs :: Textual α => p α -> ByteString -> Maybe α
- fromLazyAscii :: Textual α => ByteString -> Maybe α
- fromLazyAsciiAs :: Textual α => p α -> ByteString -> Maybe α
- fromUtf8 :: Textual α => ByteString -> Maybe α
- fromUtf8As :: Textual α => p α -> ByteString -> Maybe α
- fromLazyUtf8 :: Textual α => ByteString -> Maybe α
- fromLazyUtf8As :: Textual α => p α -> ByteString -> Maybe α

# Printing

class Printable α where #

The default printer for values of a type.

Minimal complete definition

print

Methods

print :: Printer p => α -> p #

Instances

Printable Char # |
Methods print :: Printer p => Char -> p #
Printable Double # |
Methods print :: Printer p => Double -> p #
Printable Float # |
Methods print :: Printer p => Float -> p #
Printable Int # |
Methods print :: Printer p => Int -> p #
Printable Int8 # |
Methods print :: Printer p => Int8 -> p #
Printable Int16 # |
Methods print :: Printer p => Int16 -> p #
Printable Int32 # |
Methods print :: Printer p => Int32 -> p #
Printable Int64 # |
Methods print :: Printer p => Int64 -> p #
Printable Integer # |
Methods print :: Printer p => Integer -> p #
Printable Word # |
Methods print :: Printer p => Word -> p #
Printable Word8 # |
Methods print :: Printer p => Word8 -> p #
Printable Word16 # |
Methods print :: Printer p => Word16 -> p #
Printable Word32 # |
Methods print :: Printer p => Word32 -> p #
Printable Word64 # |
Methods print :: Printer p => Word64 -> p #
Printable Text # |
Methods print :: Printer p => Text -> p #
Printable Text # |
Methods print :: Printer p => Text -> p #
Printable String # |
Methods print :: Printer p => String -> p #
Integral α => Printable (Ratio α) # |
Methods print :: Printer p => Ratio α -> p #
HasResolution α => Printable (Fixed α) # |
Methods print :: Printer p => Fixed α -> p #

maybePrint :: (Printer p, Printable α) => Maybe α -> p #

A shorthand for ``maybe` `mempty` `print``.

toString :: Printable α => α -> String #

A shorthand for ``buildString` . `print``.

toText :: Printable α => α -> Text #

A shorthand for ``buildText` . `print``.

toLazyText :: Printable α => α -> Text #

A shorthand for ``buildLazyText` . `print``.

toAscii :: Printable α => α -> ByteString #

A shorthand for ``buildAscii` . `print``.

toLazyAscii :: Printable α => α -> ByteString #

A shorthand for ``buildLazyAscii` . `print``.

toUtf8 :: Printable α => α -> ByteString #

A shorthand for ``buildUtf8` . `print``.

toLazyUtf8 :: Printable α => α -> ByteString #

A shorthand for ``buildLazyUtf8` . `print``.

# Parsing

class Printable α => Textual α where #

The default parser for values of a type, must satisfy ``fromString` (`toString` x) = `Just` x`

Minimal complete definition

textual

Methods

textual :: (Monad μ, CharParsing μ) => μ α #

Instances

Textual Char # |
Methods textual :: (Monad μ, CharParsing μ) => μ Char #
Textual Int # |
Methods textual :: (Monad μ, CharParsing μ) => μ Int #
Textual Int8 # |
Methods textual :: (Monad μ, CharParsing μ) => μ Int8 #
Textual Int16 # |
Methods textual :: (Monad μ, CharParsing μ) => μ Int16 #
Textual Int32 # |
Methods textual :: (Monad μ, CharParsing μ) => μ Int32 #
Textual Int64 # |
Methods textual :: (Monad μ, CharParsing μ) => μ Int64 #
Textual Integer # |
Methods textual :: (Monad μ, CharParsing μ) => μ Integer #
Textual Word # |
Methods textual :: (Monad μ, CharParsing μ) => μ Word #
Textual Word8 # |
Methods textual :: (Monad μ, CharParsing μ) => μ Word8 #
Textual Word16 # |
Methods textual :: (Monad μ, CharParsing μ) => μ Word16 #
Textual Word32 # |
Methods textual :: (Monad μ, CharParsing μ) => μ Word32 #
Textual Word64 # |
Methods textual :: (Monad μ, CharParsing μ) => μ Word64 #
Integral α => Textual (Ratio α) # |
Methods textual :: (Monad μ, CharParsing μ) => μ (Ratio α) #
HasResolution α => Textual (Fixed α) # |
Methods textual :: (Monad μ, CharParsing μ) => μ (Fixed α) #

## Built-in parser

data Parsed α #

Parsing result.

Constructors

Parsed α |
Malformed [String] String |

Instances

Functor Parsed # |
Methods fmap :: (a -> b) -> Parsed a -> Parsed b # (<$) :: a -> Parsed b -> Parsed a #
Applicative Parsed # |
Methods pure :: a -> Parsed a # (<*>) :: Parsed (a -> b) -> Parsed a -> Parsed b # (*>) :: Parsed a -> Parsed b -> Parsed b # (<*) :: Parsed a -> Parsed b -> Parsed a #
Foldable Parsed # |
Methods fold :: Monoid m => Parsed m -> m # foldMap :: Monoid m => (a -> m) -> Parsed a -> m # foldr :: (a -> b -> b) -> b -> Parsed a -> b # foldr' :: (a -> b -> b) -> b -> Parsed a -> b # foldl :: (b -> a -> b) -> b -> Parsed a -> b # foldl' :: (b -> a -> b) -> b -> Parsed a -> b # foldr1 :: (a -> a -> a) -> Parsed a -> a # foldl1 :: (a -> a -> a) -> Parsed a -> a # toList :: Parsed a -> [a] # null :: Parsed a -> Bool # length :: Parsed a -> Int # elem :: Eq a => a -> Parsed a -> Bool # maximum :: Ord a => Parsed a -> a # minimum :: Ord a => Parsed a -> a # sum :: Num a => Parsed a -> a # product :: Num a => Parsed a -> a #
Traversable Parsed # |
Methods traverse :: Applicative f => (a -> f b) -> Parsed a -> f (Parsed b) # sequenceA :: Applicative f => Parsed (f a) -> f (Parsed a) # mapM :: Monad m => (a -> m b) -> Parsed a -> m (Parsed b) # sequence :: Monad m => Parsed (m a) -> m (Parsed a) #
Alternative Parsed # |
Methods empty :: Parsed a # (<|>) :: Parsed a -> Parsed a -> Parsed a # some :: Parsed a -> Parsed [a] # many :: Parsed a -> Parsed [a] #
Eq α => Eq (Parsed α) # |
Methods (==) :: Parsed α -> Parsed α -> Bool # (/=) :: Parsed α -> Parsed α -> Bool #
Show α => Show (Parsed α) # |
Methods showsPrec :: Int -> Parsed α -> ShowS # show :: Parsed α -> String # showList :: [Parsed α] -> ShowS #

isParsed :: Parsed α -> Bool #

Map `Parsed` to `True` and `Malformed` to `False`.

isMalformed :: Parsed α -> Bool #

Map `Parsed` to `False` and `Malformed` to `True`.

maybeParsed :: Parsed α -> Maybe α #

Map `Parsed` values to `Just` and `Malformed` to `Nothing`.

builtInParser :: (forall μ. (Monad μ, CharParsing μ) => μ α) -> String -> Parsed α #

Use the built-in parser to parse a string. Intended for testing only.

parseString :: Textual α => String -> Parsed α #

Parse a `String` to extract the `Textual` value.

parseStringAs :: Textual α => p α -> String -> Parsed α #

Provide a hint for the type system when using `parseString`.

parseText :: Textual α => Text -> Parsed α #

Parse a `Text` to extract the `Textual` value.

parseTextAs :: Textual α => p α -> Text -> Parsed α #

Provide a hint for the type system when using `parseText`.

parseLazyText :: Textual α => Text -> Parsed α #

Parse a lazy `Text` to extract the `Textual` value.

parseLazyTextAs :: Textual α => p α -> Text -> Parsed α #

Provide a hint for the type system when using `parseLazyText`.

parseAscii :: Textual α => ByteString -> Parsed α #

Decode and parse an ASCII `ByteString` to extract the `Textual` value.

parseAsciiAs :: Textual α => p α -> ByteString -> Parsed α #

Provide a hint for the type system when using `parseAscii`.

parseLazyAscii :: Textual α => ByteString -> Parsed α #

Decode and parse a lazy ASCII `ByteString` to extract the `Textual` value.

parseLazyAsciiAs :: Textual α => ByteString -> Parsed α #

Provide a hint for the type system when using `parseLazyAscii`.

parseUtf8 :: Textual α => ByteString -> Parsed α #

Decode and parse a UTF-8 `ByteString` to extract the `Textual` value.

parseUtf8As :: Textual α => p α -> ByteString -> Parsed α #

Provide a hint for the type system when using `parseUtf8`.

parseLazyUtf8 :: Textual α => ByteString -> Parsed α #

Decode and parse a lazy UTF-8 `ByteString` to extract the `Textual` value.

parseLazyUtf8As :: Textual α => p α -> ByteString -> Parsed α #

Provide a hint for the type system when using `parseLazyUtf8`.

fromString :: Textual α => String -> Maybe α #

A shorthand for ``maybeParsed` . `parseString``

fromStringAs :: Textual α => p α -> String -> Maybe α #

Provide a hint for the type system when using `fromString`.

fromText :: Textual α => Text -> Maybe α #

A shorthand for ``maybeParsed` . `parseText``

fromTextAs :: Textual α => p α -> Text -> Maybe α #

Provide a hint for the type system when using `fromText`.

fromLazyText :: Textual α => Text -> Maybe α #

A shorthand for ``maybeParsed` . `parseLazyText``

fromLazyTextAs :: Textual α => p α -> Text -> Maybe α #

Provide a hint for the type system when using `fromLazyText`.

fromAscii :: Textual α => ByteString -> Maybe α #

A shorthand for ``maybeParsed` . `parseAscii``

fromAsciiAs :: Textual α => p α -> ByteString -> Maybe α #

Provide a hint for the type system when using `fromAscii`.

fromLazyAscii :: Textual α => ByteString -> Maybe α #

A shorthand for ``maybeParsed` . `parseLazyAscii``

fromLazyAsciiAs :: Textual α => p α -> ByteString -> Maybe α #

Provide a hint for the type system when using `fromLazyAscii`.

fromUtf8 :: Textual α => ByteString -> Maybe α #

A shorthand for ``maybeParsed` . `parseUtf8``

fromUtf8As :: Textual α => p α -> ByteString -> Maybe α #

Provide a hint for the type system when using `fromUtf8`.

fromLazyUtf8 :: Textual α => ByteString -> Maybe α #

A shorthand for ``maybeParsed` . `parseLazyUtf8``

fromLazyUtf8As :: Textual α => p α -> ByteString -> Maybe α #

Provide a hint for the type system when using `fromLazyUtf8`.