base-4.10.1.0: Basic libraries

Copyright | (c) Ross Paterson 2013
License | BSD-style (see the file LICENSE)
Maintainer | libraries@haskell.org
Stability | experimental
Portability | portable
Safe Haskell | Safe
Language | Haskell2010

Data.Functor.Classes

Contents

- Liftings of Prelude classes
  - For unary constructors
  - For binary constructors
- Helper functions
  - Obsolete helpers

Description

Liftings of the Prelude classes `Eq`, `Ord`, `Read` and `Show` to unary and binary type constructors.

These classes are needed to express the constraints on arguments of transformers in portable Haskell. Thus for a new transformer `T`, one might write instances like

    instance (Eq1 f) => Eq1 (T f) where ...
    instance (Ord1 f) => Ord1 (T f) where ...
    instance (Read1 f) => Read1 (T f) where ...
    instance (Show1 f) => Show1 (T f) where ...

If these instances can be defined, defining instances of the base classes is mechanical:

    instance (Eq1 f, Eq a) => Eq (T f a) where (==) = eq1
    instance (Ord1 f, Ord a) => Ord (T f a) where compare = compare1
    instance (Read1 f, Read a) => Read (T f a) where
      readPrec     = readPrec1
      readListPrec = readListPrecDefault
    instance (Show1 f, Show a) => Show (T f a) where showsPrec = showsPrec1

Since: 4.9.0.0

Synopsis

- class Eq1 f where
- eq1 :: (Eq1 f, Eq a) => f a -> f a -> Bool
- class Eq1 f => Ord1 f where
- compare1 :: (Ord1 f, Ord a) => f a -> f a -> Ordering
- class Read1 f where
- readsPrec1 :: (Read1 f, Read a) => Int -> ReadS (f a)
- readPrec1 :: (Read1 f, Read a) => ReadPrec (f a)
- liftReadListDefault :: Read1 f => (Int -> ReadS a) -> ReadS [a] -> ReadS [f a]
- liftReadListPrecDefault :: Read1 f => ReadPrec a -> ReadPrec [a] -> ReadPrec [f a]
- class Show1 f where
- showsPrec1 :: (Show1 f, Show a) => Int -> f a -> ShowS
- class Eq2 f where
- eq2 :: (Eq2 f, Eq a, Eq b) => f a b -> f a b -> Bool
- class Eq2 f => Ord2 f where
- compare2 :: (Ord2 f, Ord a, Ord b) => f a b -> f a b -> Ordering
- class Read2 f where
- readsPrec2 :: (Read2 f, Read a, Read b) => Int -> ReadS (f a b)
- readPrec2 :: (Read2 f, Read a, Read b) => ReadPrec (f a b)
- liftReadList2Default :: Read2 f => (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [f a b]
- liftReadListPrec2Default :: Read2 f => ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [f a b]
- class Show2 f where
- showsPrec2 :: (Show2 f, Show a, Show b) => Int -> f a b -> ShowS
- readsData :: (String -> ReadS a) -> Int -> ReadS a
- readData :: ReadPrec a -> ReadPrec a
- readsUnaryWith :: (Int -> ReadS a) -> String -> (a -> t) -> String -> ReadS t
- readUnaryWith :: ReadPrec a -> String -> (a -> t) -> ReadPrec t
- readsBinaryWith :: (Int -> ReadS a) -> (Int -> ReadS b) -> String -> (a -> b -> t) -> String -> ReadS t
- readBinaryWith :: ReadPrec a -> ReadPrec b -> String -> (a -> b -> t) -> ReadPrec t
- showsUnaryWith :: (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
- showsBinaryWith :: (Int -> a -> ShowS) -> (Int -> b -> ShowS) -> String -> Int -> a -> b -> ShowS
- readsUnary :: Read a => String -> (a -> t) -> String -> ReadS t
- readsUnary1 :: (Read1 f, Read a) => String -> (f a -> t) -> String -> ReadS t
- readsBinary1 :: (Read1 f, Read1 g, Read a) => String -> (f a -> g a -> t) -> String -> ReadS t
- showsUnary :: Show a => String -> Int -> a -> ShowS
- showsUnary1 :: (Show1 f, Show a) => String -> Int -> f a -> ShowS
- showsBinary1 :: (Show1 f, Show1 g, Show a) => String -> Int -> f a -> g a -> ShowS

# Liftings of Prelude classes

## For unary constructors

class Eq1 f where #

Lifting of the `Eq` class to unary type constructors.

Since: 4.9.0.0

Minimal complete definition

liftEq

Methods

liftEq :: (a -> b -> Bool) -> f a -> f b -> Bool #

Lift an equality test through the type constructor.

The function will usually be applied to an equality function, but the more general type ensures that the implementation uses it to compare elements of the first container with elements of the second.

Since: 4.9.0.0

Instances

Eq1 [] # | Since: 4.9.0.0
Methods liftEq :: (a -> b -> Bool) -> [a] -> [b] -> Bool #
Eq1 Maybe # | Since: 4.9.0.0
Methods liftEq :: (a -> b -> Bool) -> Maybe a -> Maybe b -> Bool #
Eq1 Identity # | Since: 4.9.0.0
Methods liftEq :: (a -> b -> Bool) -> Identity a -> Identity b -> Bool #
Eq1 NonEmpty # | Since: 4.10.0.0
Methods liftEq :: (a -> b -> Bool) -> NonEmpty a -> NonEmpty b -> Bool #
Eq a => Eq1 (Either a) # | Since: 4.9.0.0
Methods liftEq :: (a -> b -> Bool) -> Either a a -> Either a b -> Bool #
Eq a => Eq1 ((,) a) # | Since: 4.9.0.0
Methods liftEq :: (a -> b -> Bool) -> (a, a) -> (a, b) -> Bool #
Eq1 (Proxy *) # | Since: 4.9.0.0
Methods liftEq :: (a -> b -> Bool) -> Proxy * a -> Proxy * b -> Bool #
Eq a => Eq1 (Const * a) # | Since: 4.9.0.0
Methods liftEq :: (a -> b -> Bool) -> Const * a a -> Const * a b -> Bool #
(Eq1 f, Eq1 g) => Eq1 (Sum * f g) # | Since: 4.9.0.0
Methods liftEq :: (a -> b -> Bool) -> Sum * f g a -> Sum * f g b -> Bool #
(Eq1 f, Eq1 g) => Eq1 (Product * f g) # | Since: 4.9.0.0
Methods liftEq :: (a -> b -> Bool) -> Product * f g a -> Product * f g b -> Bool #
(Eq1 f, Eq1 g) => Eq1 (Compose * * f g) # | Since: 4.9.0.0
Methods liftEq :: (a -> b -> Bool) -> Compose * * f g a -> Compose * * f g b -> Bool #

eq1 :: (Eq1 f, Eq a) => f a -> f a -> Bool #

Lift the standard `(`==`)` function through the type constructor.

Since: 4.9.0.0

class Eq1 f => Ord1 f where #

Lifting of the `Ord` class to unary type constructors.

Since: 4.9.0.0

Minimal complete definition

liftCompare

Methods

liftCompare :: (a -> b -> Ordering) -> f a -> f b -> Ordering #

Lift a `compare` function through the type constructor.

The function will usually be applied to a comparison function, but the more general type ensures that the implementation uses it to compare elements of the first container with elements of the second.

Since: 4.9.0.0

Instances

Ord1 [] # | Since: 4.9.0.0
Methods liftCompare :: (a -> b -> Ordering) -> [a] -> [b] -> Ordering #
Ord1 Maybe # | Since: 4.9.0.0
Methods liftCompare :: (a -> b -> Ordering) -> Maybe a -> Maybe b -> Ordering #
Ord1 Identity # | Since: 4.9.0.0
Methods liftCompare :: (a -> b -> Ordering) -> Identity a -> Identity b -> Ordering #
Ord1 NonEmpty # | Since: 4.10.0.0
Methods liftCompare :: (a -> b -> Ordering) -> NonEmpty a -> NonEmpty b -> Ordering #
Ord a => Ord1 (Either a) # | Since: 4.9.0.0
Methods liftCompare :: (a -> b -> Ordering) -> Either a a -> Either a b -> Ordering #
Ord a => Ord1 ((,) a) # | Since: 4.9.0.0
Methods liftCompare :: (a -> b -> Ordering) -> (a, a) -> (a, b) -> Ordering #
Ord1 (Proxy *) # | Since: 4.9.0.0
Methods liftCompare :: (a -> b -> Ordering) -> Proxy * a -> Proxy * b -> Ordering #
Ord a => Ord1 (Const * a) # | Since: 4.9.0.0
Methods liftCompare :: (a -> b -> Ordering) -> Const * a a -> Const * a b -> Ordering #
(Ord1 f, Ord1 g) => Ord1 (Sum * f g) # | Since: 4.9.0.0
Methods liftCompare :: (a -> b -> Ordering) -> Sum * f g a -> Sum * f g b -> Ordering #
(Ord1 f, Ord1 g) => Ord1 (Product * f g) # | Since: 4.9.0.0
Methods liftCompare :: (a -> b -> Ordering) -> Product * f g a -> Product * f g b -> Ordering #
(Ord1 f, Ord1 g) => Ord1 (Compose * * f g) # | Since: 4.9.0.0
Methods liftCompare :: (a -> b -> Ordering) -> Compose * * f g a -> Compose * * f g b -> Ordering #

compare1 :: (Ord1 f, Ord a) => f a -> f a -> Ordering #

Lift the standard `compare` function through the type constructor.

Since: 4.9.0.0

class Read1 f where #

Lifting of the `Read` class to unary type constructors.

Both `liftReadsPrec` and `liftReadPrec` exist to match the interface provided in the `Read` type class, but it is recommended to implement `Read1` instances using `liftReadPrec` as opposed to `liftReadsPrec`, since the former is more efficient than the latter. For example:

    instance Read1 T where
      liftReadPrec     = ...
      liftReadListPrec = liftReadListPrecDefault

For more information, refer to the documentation for the `Read` class.

Since: 4.9.0.0

Minimal complete definition

liftReadsPrec | liftReadPrec

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a) #

`readsPrec` function for an application of the type constructor based on `readsPrec` and `readList` functions for the argument type.

Since: 4.9.0.0

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [f a] #

`readList` function for an application of the type constructor based on `readsPrec` and `readList` functions for the argument type. The default implementation using standard list syntax is correct for most types.

Since: 4.9.0.0

liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (f a) #

`readPrec` function for an application of the type constructor based on `readPrec` and `readListPrec` functions for the argument type.

Since: 4.10.0.0

liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [f a] #

`readListPrec` function for an application of the type constructor based on `readPrec` and `readListPrec` functions for the argument type.

The default definition uses `liftReadList`. Instances that define `liftReadPrec` should also define `liftReadListPrec` as `liftReadListPrecDefault`.

Since: 4.10.0.0

Instances

Read1 [] # | Since: 4.9.0.0
Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS [a] # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [[a]] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [a] # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [[a]] #
Read1 Maybe # | Since: 4.9.0.0
Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Maybe a) # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Maybe a] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Maybe a) # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Maybe a] #
Read1 Identity # | Since: 4.9.0.0
Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Identity a) # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Identity a] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Identity a) # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Identity a] #
Read1 NonEmpty # | Since: 4.10.0.0
Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (NonEmpty a) # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [NonEmpty a] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (NonEmpty a) # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [NonEmpty a] #
Read a => Read1 (Either a) # | Since: 4.9.0.0
Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Either a a) # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Either a a] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Either a a) # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Either a a] #
Read a => Read1 ((,) a) # | Since: 4.9.0.0
Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (a, a) # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [(a, a)] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (a, a) # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [(a, a)] #
Read1 (Proxy *) # | Since: 4.9.0.0
Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Proxy * a) # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Proxy * a] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Proxy * a) # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Proxy * a] #
Read a => Read1 (Const * a) # | Since: 4.9.0.0
Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Const * a a) # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Const * a a] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Const * a a) # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Const * a a] #
(Read1 f, Read1 g) => Read1 (Sum * f g) # | Since: 4.9.0.0
Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Sum * f g a) # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Sum * f g a] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Sum * f g a) # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Sum * f g a] #
(Read1 f, Read1 g) => Read1 (Product * f g) # | Since: 4.9.0.0
Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Product * f g a) # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Product * f g a] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Product * f g a) # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Product * f g a] #
(Read1 f, Read1 g) => Read1 (Compose * * f g) # | Since: 4.9.0.0
Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Compose * * f g a) # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Compose * * f g a] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Compose * * f g a) # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Compose * * f g a] #

readsPrec1 :: (Read1 f, Read a) => Int -> ReadS (f a) #

Lift the standard `readsPrec` and `readList` functions through the type constructor.

Since: 4.9.0.0

readPrec1 :: (Read1 f, Read a) => ReadPrec (f a) #

Lift the standard `readPrec` and `readListPrec` functions through the type constructor.

Since: 4.10.0.0

liftReadListDefault :: Read1 f => (Int -> ReadS a) -> ReadS [a] -> ReadS [f a] #

A possible replacement definition for the `liftReadList` method. This is only needed for `Read1` instances where `liftReadListPrec` isn't defined as `liftReadListPrecDefault`.

Since: 4.10.0.0

liftReadListPrecDefault :: Read1 f => ReadPrec a -> ReadPrec [a] -> ReadPrec [f a] #

A possible replacement definition for the `liftReadListPrec` method, defined using `liftReadPrec`.

Since: 4.10.0.0

class Show1 f where #

Lifting of the `Show` class to unary type constructors.

Since: 4.9.0.0

Minimal complete definition

liftShowsPrec

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS #

`showsPrec` function for an application of the type constructor based on `showsPrec` and `showList` functions for the argument type.

Since: 4.9.0.0

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS #

`showList` function for an application of the type constructor based on `showsPrec` and `showList` functions for the argument type. The default implementation using standard list syntax is correct for most types.

Since: 4.9.0.0

Instances

Show1 [] # | Since: 4.9.0.0
Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> [a] -> ShowS # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [[a]] -> ShowS #
Show1 Maybe # | Since: 4.9.0.0
Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Maybe a -> ShowS # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Maybe a] -> ShowS #
Show1 Identity # | Since: 4.9.0.0
Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Identity a -> ShowS # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Identity a] -> ShowS #
Show1 NonEmpty # | Since: 4.10.0.0
Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> NonEmpty a -> ShowS # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [NonEmpty a] -> ShowS #
Show a => Show1 (Either a) # | Since: 4.9.0.0
Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Either a a -> ShowS # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Either a a] -> ShowS #
Show a => Show1 ((,) a) # | Since: 4.9.0.0
Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> (a, a) -> ShowS # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [(a, a)] -> ShowS #
Show1 (Proxy *) # | Since: 4.9.0.0
Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Proxy * a -> ShowS # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Proxy * a] -> ShowS #
Show a => Show1 (Const * a) # | Since: 4.9.0.0
Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Const * a a -> ShowS # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Const * a a] -> ShowS #
(Show1 f, Show1 g) => Show1 (Sum * f g) # | Since: 4.9.0.0
Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Sum * f g a -> ShowS # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Sum * f g a] -> ShowS #
(Show1 f, Show1 g) => Show1 (Product * f g) # | Since: 4.9.0.0
Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Product * f g a -> ShowS # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Product * f g a] -> ShowS #
(Show1 f, Show1 g) => Show1 (Compose * * f g) # | Since: 4.9.0.0
Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Compose * * f g a -> ShowS # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Compose * * f g a] -> ShowS #

showsPrec1 :: (Show1 f, Show a) => Int -> f a -> ShowS #

Lift the standard `showsPrec` and `showList` functions through the type constructor.

Since: 4.9.0.0

## For binary constructors

class Eq2 f where #

Lifting of the `Eq` class to binary type constructors.

Since: 4.9.0.0

Minimal complete definition

liftEq2

Methods

liftEq2 :: (a -> b -> Bool) -> (c -> d -> Bool) -> f a c -> f b d -> Bool #

Lift equality tests through the type constructor.

The function will usually be applied to equality functions, but the more general type ensures that the implementation uses them to compare elements of the first container with elements of the second.

Since: 4.9.0.0

Instances

Eq2 Either # | Since: 4.9.0.0
Methods liftEq2 :: (a -> b -> Bool) -> (c -> d -> Bool) -> Either a c -> Either b d -> Bool #
Eq2 (,) # | Since: 4.9.0.0
Methods liftEq2 :: (a -> b -> Bool) -> (c -> d -> Bool) -> (a, c) -> (b, d) -> Bool #
Eq2 (Const *) # | Since: 4.9.0.0
Methods liftEq2 :: (a -> b -> Bool) -> (c -> d -> Bool) -> Const * a c -> Const * b d -> Bool #

eq2 :: (Eq2 f, Eq a, Eq b) => f a b -> f a b -> Bool #

Lift the standard `(`==`)` function through the type constructor.

Since: 4.9.0.0

class Eq2 f => Ord2 f where #

Lifting of the `Ord` class to binary type constructors.

Since: 4.9.0.0

Minimal complete definition

liftCompare2

Methods

liftCompare2 :: (a -> b -> Ordering) -> (c -> d -> Ordering) -> f a c -> f b d -> Ordering #

Lift `compare` functions through the type constructor.

The function will usually be applied to comparison functions, but the more general type ensures that the implementation uses them to compare elements of the first container with elements of the second.

Since: 4.9.0.0

Instances

Ord2 Either # | Since: 4.9.0.0
Methods liftCompare2 :: (a -> b -> Ordering) -> (c -> d -> Ordering) -> Either a c -> Either b d -> Ordering #
Ord2 (,) # | Since: 4.9.0.0
Methods liftCompare2 :: (a -> b -> Ordering) -> (c -> d -> Ordering) -> (a, c) -> (b, d) -> Ordering #
Ord2 (Const *) # | Since: 4.9.0.0
Methods liftCompare2 :: (a -> b -> Ordering) -> (c -> d -> Ordering) -> Const * a c -> Const * b d -> Ordering #

compare2 :: (Ord2 f, Ord a, Ord b) => f a b -> f a b -> Ordering #

Lift the standard `compare` function through the type constructor.

Since: 4.9.0.0

class Read2 f where #

Lifting of the `Read` class to binary type constructors.

Both `liftReadsPrec2` and `liftReadPrec2` exist to match the interface provided in the `Read` type class, but it is recommended to implement `Read2` instances using `liftReadPrec2` as opposed to `liftReadsPrec2`, since the former is more efficient than the latter. For example:

    instance Read2 T where
      liftReadPrec2     = ...
      liftReadListPrec2 = liftReadListPrec2Default

For more information, refer to the documentation for the `Read` class. @since 4.9.0.0

Minimal complete definition

liftReadsPrec2 | liftReadPrec2

Methods

liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (f a b) #

`readsPrec` function for an application of the type constructor based on `readsPrec` and `readList` functions for the argument types.

Since: 4.9.0.0

liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [f a b] #

`readList` function for an application of the type constructor based on `readsPrec` and `readList` functions for the argument types. The default implementation using standard list syntax is correct for most types.

Since: 4.9.0.0

liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (f a b) #

`readPrec` function for an application of the type constructor based on `readPrec` and `readListPrec` functions for the argument types.

Since: 4.10.0.0

liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [f a b] #

`readListPrec` function for an application of the type constructor based on `readPrec` and `readListPrec` functions for the argument types.

The default definition uses `liftReadList2`. Instances that define `liftReadPrec2` should also define `liftReadListPrec2` as `liftReadListPrec2Default`.

Since: 4.10.0.0

Instances

Read2 Either # | Since: 4.9.0.0

Methods

liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (Either a b) #

liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [Either a b] #

liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (Either a b) #

liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [Either a b] #

Read2 (,) # | Since: 4.9.0.0

Methods

liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (a, b) #

liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [(a, b)] #

liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (a, b) #

liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [(a, b)] #

Read2 (Const *) # | Since: 4.9.0.0

Methods

liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (Const * a b) #

liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [Const * a b] #

liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (Const * a b) #

liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [Const * a b] #

readsPrec2 :: (Read2 f, Read a, Read b) => Int -> ReadS (f a b) #

Lift the standard `readsPrec` function through the type constructor.

Since: 4.9.0.0

readPrec2 :: (Read2 f, Read a, Read b) => ReadPrec (f a b) #

Lift the standard `readPrec` function through the type constructor.

Since: 4.10.0.0

liftReadList2Default :: Read2 f => (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [f a b] #

A possible replacement definition for the `liftReadList2` method. This is only needed for `Read2` instances where `liftReadListPrec2` isn't defined as `liftReadListPrec2Default`.

Since: 4.10.0.0

liftReadListPrec2Default :: Read2 f => ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [f a b] #

A possible replacement definition for the `liftReadListPrec2` method, defined using `liftReadPrec2`.

Since: 4.10.0.0

class Show2 f where #

Lifting of the `Show` class to binary type constructors.

Since: 4.9.0.0

Minimal complete definition

liftShowsPrec2

Methods

liftShowsPrec2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> Int -> f a b -> ShowS #

`showsPrec` function for an application of the type constructor based on `showsPrec` and `showList` functions for the argument types.

Since: 4.9.0.0

liftShowList2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> [f a b] -> ShowS #

`showList` function for an application of the type constructor based on `showsPrec` and `showList` functions for the argument types. The default implementation using standard list syntax is correct for most types.

Since: 4.9.0.0

Instances

Show2 Either # | Since: 4.9.0.0
Methods liftShowsPrec2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> Int -> Either a b -> ShowS # liftShowList2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> [Either a b] -> ShowS #
Show2 (,) # | Since: 4.9.0.0
Methods liftShowsPrec2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> Int -> (a, b) -> ShowS # liftShowList2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> [(a, b)] -> ShowS #
Show2 (Const *) # | Since: 4.9.0.0
Methods liftShowsPrec2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> Int -> Const * a b -> ShowS # liftShowList2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> [Const * a b] -> ShowS #

showsPrec2 :: (Show2 f, Show a, Show b) => Int -> f a b -> ShowS #

Lift the standard `showsPrec` function through the type constructor.

Since: 4.9.0.0

# Helper functions

These functions can be used to assemble `Read` and `Show` instances for new algebraic types. For example, given the definition

    data T f a = Zero a | One (f a) | Two a (f a)

a standard `Read1` instance may be defined as

    instance (Read1 f) => Read1 (T f) where
        liftReadPrec rp rl = readData $
            readUnaryWith rp "Zero" Zero <|>
            readUnaryWith (liftReadPrec rp rl) "One" One <|>
            readBinaryWith rp (liftReadPrec rp rl) "Two" Two
        liftReadListPrec = liftReadListPrecDefault

and the corresponding `Show1` instance as

    instance (Show1 f) => Show1 (T f) where
        liftShowsPrec sp _ d (Zero x) =
            showsUnaryWith sp "Zero" d x
        liftShowsPrec sp sl d (One x) =
            showsUnaryWith (liftShowsPrec sp sl) "One" d x
        liftShowsPrec sp sl d (Two x y) =
            showsBinaryWith sp (liftShowsPrec sp sl) "Two" d x y

readsData :: (String -> ReadS a) -> Int -> ReadS a #

``readsData` p d` is a parser for datatypes where each alternative begins with a data constructor. It parses the constructor and passes it to `p`. Parsers for various constructors can be constructed with `readsUnary`, `readsUnary1` and `readsBinary1`, and combined with `mappend` from the `Monoid` class.

Since: 4.9.0.0

readData :: ReadPrec a -> ReadPrec a #

``readData` p` is a parser for datatypes where each alternative begins with a data constructor. It parses the constructor and passes it to `p`. Parsers for various constructors can be constructed with `readUnaryWith` and `readBinaryWith`, and combined with '(|)' from the `Alternative` class.

Since: 4.10.0.0

readsUnaryWith :: (Int -> ReadS a) -> String -> (a -> t) -> String -> ReadS t #

``readsUnaryWith` rp n c n'` matches the name of a unary data constructor and then parses its argument using `rp`.

Since: 4.9.0.0

readUnaryWith :: ReadPrec a -> String -> (a -> t) -> ReadPrec t #

``readUnaryWith` rp n c'` matches the name of a unary data constructor and then parses its argument using `rp`.

Since: 4.10.0.0

readsBinaryWith :: (Int -> ReadS a) -> (Int -> ReadS b) -> String -> (a -> b -> t) -> String -> ReadS t #

``readsBinaryWith` rp1 rp2 n c n'` matches the name of a binary data constructor and then parses its arguments using `rp1` and `rp2` respectively.

Since: 4.9.0.0

readBinaryWith :: ReadPrec a -> ReadPrec b -> String -> (a -> b -> t) -> ReadPrec t #

``readBinaryWith` rp1 rp2 n c'` matches the name of a binary data constructor and then parses its arguments using `rp1` and `rp2` respectively.

Since: 4.10.0.0

showsUnaryWith :: (Int -> a -> ShowS) -> String -> Int -> a -> ShowS #

``showsUnaryWith` sp n d x` produces the string representation of a unary data constructor with name `n` and argument `x`, in precedence context `d`.

Since: 4.9.0.0

showsBinaryWith :: (Int -> a -> ShowS) -> (Int -> b -> ShowS) -> String -> Int -> a -> b -> ShowS #

``showsBinaryWith` sp1 sp2 n d x y` produces the string representation of a binary data constructor with name `n` and arguments `x` and `y`, in precedence context `d`.

Since: 4.9.0.0

## Obsolete helpers

readsUnary :: Read a => String -> (a -> t) -> String -> ReadS t #

Deprecated: Use readsUnaryWith to define liftReadsPrec

``readsUnary` n c n'` matches the name of a unary data constructor and then parses its argument using `readsPrec`.

Since: 4.9.0.0

readsUnary1 :: (Read1 f, Read a) => String -> (f a -> t) -> String -> ReadS t #

Deprecated: Use readsUnaryWith to define liftReadsPrec

``readsUnary1` n c n'` matches the name of a unary data constructor and then parses its argument using `readsPrec1`.

Since: 4.9.0.0

readsBinary1 :: (Read1 f, Read1 g, Read a) => String -> (f a -> g a -> t) -> String -> ReadS t #

Deprecated: Use readsBinaryWith to define liftReadsPrec

``readsBinary1` n c n'` matches the name of a binary data constructor and then parses its arguments using `readsPrec1`.

Since: 4.9.0.0

showsUnary :: Show a => String -> Int -> a -> ShowS #

Deprecated: Use showsUnaryWith to define liftShowsPrec

``showsUnary` n d x` produces the string representation of a unary data constructor with name `n` and argument `x`, in precedence context `d`.

Since: 4.9.0.0

showsUnary1 :: (Show1 f, Show a) => String -> Int -> f a -> ShowS #

Deprecated: Use showsUnaryWith to define liftShowsPrec

``showsUnary1` n d x` produces the string representation of a unary data constructor with name `n` and argument `x`, in precedence context `d`.

Since: 4.9.0.0

showsBinary1 :: (Show1 f, Show1 g, Show a) => String -> Int -> f a -> g a -> ShowS #

Deprecated: Use showsBinaryWith to define liftShowsPrec

``showsBinary1` n d x y` produces the string representation of a binary data constructor with name `n` and arguments `x` and `y`, in precedence context `d`.

Since: 4.9.0.0