| Safe Haskell | Safe-Inferred | 
|---|---|
| Language | Haskell2010 | 
AutoLift
Contents
Description
Synopsis
- newtype Reflected1 f a = Reflected1 (f a)
- newtype Reflected2 f a b = Reflected2 (f a b)
- class Show1 (f :: TYPE LiftedRep -> TYPE LiftedRep) where
- class Read a where
- class Read1 (f :: Type -> Type) where- liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
- liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [f a]
- liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (f a)
- liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [f a]
 
- data ReadPrec a
Documentation
newtype Reflected1 f a Source #
A newtype wrapper to derive Show1 fRead1 f
instance Show a => Show (f a) instance Read a => Read (f a)
Example
Suppose you define a new type constructor Foo, and
 derived its Show instance.
>>>data Foo a = Foo [a] Int a deriving Show
The derived Show (Foo a) instance is defined for all a with Show a instance.
instance Show a => Show (Foo a)
Reflected1 allows you to derive Show1 Foo
>>>:set -XStandaloneDeriving -XDerivingVia>>>deriving via (Reflected1 Foo) instance Show1 Foo
Let's try the derived Show1 instance, by showing Foo Bool, where
 True is shown as yes and False as no, instead of the normal Show Bool instance.
>>>import Text.Show (showListWith)>>>let yesno b = (++) (if b then "yes" else "no")>>>liftShowsPrec (const yesno) (showListWith yesno) 0 (Foo [True, False] 5 False) """Foo [yes,no] 5 no"
Constructors
| Reflected1 (f a) | 
Instances
| (forall a. Read a => Read (f a), forall xx yy. Coercible xx yy => Coercible (f xx) (f yy)) => Read1 (Reflected1 f) Source # | |
| Defined in AutoLift Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Reflected1 f a) # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Reflected1 f a] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Reflected1 f a) # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Reflected1 f a] # | |
| (forall a. Show a => Show (f a), forall xx yy. Coercible xx yy => Coercible (f xx) (f yy)) => Show1 (Reflected1 f) Source # | |
| Defined in AutoLift Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Reflected1 f a -> ShowS # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Reflected1 f a] -> ShowS # | |
newtype Reflected2 f a b Source #
A newtype wrapper to derive Show2 fRead2 f
instance (Show a, Show b) => Show (f a b) instance (Read a, Read b) => Read (f a b)
Example
Suppose you define a new type constructor Bar, and
 derived its Show instance.
>>>data Bar a b = Bar [(Int,a,b)] deriving Show
The derived Show (Bar a b) instance is defined for all a and b with Show instances.
instance (Show a, Show b) => Show (Bar a b)
Reflected2 allows you to derive Show2 Bar
>>>:set -XStandaloneDeriving -XDerivingVia>>>deriving via (Reflected2 Bar) instance Show2 Bar
Let's try the derived Show2 instance by showing Bar Bool Char, where
 True is shown as yes and False as no, instead of the normal Show Bool instance.
>>>import Text.Show (showListWith)>>>let yesno b = (++) (if b then "yes" else "no")>>>liftShowsPrec2 (const yesno) (showListWith yesno) showsPrec showList 0 (Bar [(1, True, 'A'), (2, False, 'B')]) """Bar [(1,yes,'A'),(2,no,'B')]"
Constructors
| Reflected2 (f a b) | 
Instances
| (forall a b. (Read a, Read b) => Read (f a b), forall x1 y1 x2 y2. (Coercible x1 y1, Coercible x2 y2) => Coercible (f x1 x2) (f y1 y2)) => Read2 (Reflected2 f) Source # | |
| Defined in AutoLift Methods liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (Reflected2 f a b) # liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [Reflected2 f a b] # liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (Reflected2 f a b) # liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [Reflected2 f a b] # | |
| (forall a b. (Show a, Show b) => Show (f a b), forall x1 y1 x2 y2. (Coercible x1 y1, Coercible x2 y2) => Coercible (f x1 x2) (f y1 y2)) => Show2 (Reflected2 f) Source # | |
Reexports
class Show1 (f :: TYPE LiftedRep -> TYPE LiftedRep) where #
Lifting of the Show class to unary type constructors.
Since: base-4.9.0.0
Minimal complete definition
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: base-4.9.0.0
liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS #
Instances
| Show1 Complex | 
 Since: base-4.16.0.0 | 
| Show1 Identity | Since: base-4.9.0.0 | 
| Show1 Down | Since: base-4.12.0.0 | 
| Show1 NonEmpty | Since: base-4.10.0.0 | 
| Show1 Maybe | Since: base-4.9.0.0 | 
| Show1 Solo | Since: base-4.15 | 
| Show1 [] | Since: base-4.9.0.0 | 
| Defined in Data.Functor.Classes | |
| (forall a. Show a => Show (f a), forall xx yy. Coercible xx yy => Coercible (f xx) (f yy)) => Show1 (Reflected1 f) Source # | |
| Defined in AutoLift Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Reflected1 f a -> ShowS # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Reflected1 f a] -> ShowS # | |
| Show a => Show1 (Either a) | Since: base-4.9.0.0 | 
| Show1 (Proxy :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 | 
| Show a => Show1 ((,) a) | Since: base-4.9.0.0 | 
| Defined in Data.Functor.Classes | |
| Show a => Show1 (Const a :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 | 
| (Show a, Show b) => Show1 ((,,) a b) | Since: base-4.16.0.0 | 
| Defined in Data.Functor.Classes | |
| (Show a, Show b, Show c) => Show1 ((,,,) a b c) | Since: base-4.16.0.0 | 
| Defined in Data.Functor.Classes | |
Parsing of Strings, producing values.
Derived instances of Read make the following assumptions, which
 derived instances of Show obey:
- If the constructor is defined to be an infix operator, then the
   derived Readinstance will parse only infix applications of the constructor (not the prefix form).
- Associativity is not used to reduce the occurrence of parentheses, although precedence may be.
- If the constructor is defined using record syntax, the derived Readwill parse only the record-syntax form, and furthermore, the fields must be given in the same order as the original declaration.
- The derived Readinstance allows arbitrary Haskell whitespace between tokens of the input string. Extra parentheses are also allowed.
For example, given the declarations
infixr 5 :^: data Tree a = Leaf a | Tree a :^: Tree a
the derived instance of Read in Haskell 2010 is equivalent to
instance (Read a) => Read (Tree a) where
        readsPrec d r =  readParen (d > app_prec)
                         (\r -> [(Leaf m,t) |
                                 ("Leaf",s) <- lex r,
                                 (m,t) <- readsPrec (app_prec+1) s]) r
                      ++ readParen (d > up_prec)
                         (\r -> [(u:^:v,w) |
                                 (u,s) <- readsPrec (up_prec+1) r,
                                 (":^:",t) <- lex s,
                                 (v,w) <- readsPrec (up_prec+1) t]) r
          where app_prec = 10
                up_prec = 5Note that right-associativity of :^: is unused.
The derived instance in GHC is equivalent to
instance (Read a) => Read (Tree a) where
        readPrec = parens $ (prec app_prec $ do
                                 Ident "Leaf" <- lexP
                                 m <- step readPrec
                                 return (Leaf m))
                     +++ (prec up_prec $ do
                                 u <- step readPrec
                                 Symbol ":^:" <- lexP
                                 v <- step readPrec
                                 return (u :^: v))
          where app_prec = 10
                up_prec = 5
        readListPrec = readListPrecDefaultWhy do both readsPrec and readPrec exist, and why does GHC opt to
 implement readPrec in derived Read instances instead of readsPrec?
 The reason is that readsPrec is based on the ReadS type, and although
 ReadS is mentioned in the Haskell 2010 Report, it is not a very efficient
 parser data structure.
readPrec, on the other hand, is based on a much more efficient ReadPrec
 datatype (a.k.a "new-style parsers"), but its definition relies on the use
 of the RankNTypes language extension. Therefore, readPrec (and its
 cousin, readListPrec) are marked as GHC-only. Nevertheless, it is
 recommended to use readPrec instead of readsPrec whenever possible
 for the efficiency improvements it brings.
As mentioned above, derived Read instances in GHC will implement
 readPrec instead of readsPrec. The default implementations of
 readsPrec (and its cousin, readList) will simply use readPrec under
 the hood. If you are writing a Read instance by hand, it is recommended
 to write it like so:
instanceReadT wherereadPrec= ...readListPrec=readListPrecDefault
Methods
Arguments
| :: Int | the operator precedence of the enclosing
 context (a number from  | 
| -> ReadS a | 
attempts to parse a value from the front of the string, returning a list of (parsed value, remaining string) pairs. If there is no successful parse, the returned list is empty.
Derived instances of Read and Show satisfy the following:
That is, readsPrec parses the string produced by
 showsPrec, and delivers the value that
 showsPrec started with.
The method readList is provided to allow the programmer to
 give a specialised way of parsing lists of values.
 For example, this is used by the predefined Read instance of
 the Char type, where values of type String should be are
 expected to use double quotes, rather than square brackets.
Proposed replacement for readsPrec using new-style parsers (GHC only).
readListPrec :: ReadPrec [a] #
Proposed replacement for readList using new-style parsers (GHC only).
 The default definition uses readList.  Instances that define readPrec
 should also define readListPrec as readListPrecDefault.
Instances
| Read ExitCode | |
| Read SomeChar | |
| Read SomeSymbol | Since: base-4.7.0.0 | 
| Defined in GHC.TypeLits Methods readsPrec :: Int -> ReadS SomeSymbol # readList :: ReadS [SomeSymbol] # readPrec :: ReadPrec SomeSymbol # readListPrec :: ReadPrec [SomeSymbol] # | |
| Read SomeNat | Since: base-4.7.0.0 | 
| Read GeneralCategory | Since: base-2.1 | 
| Defined in GHC.Read Methods readsPrec :: Int -> ReadS GeneralCategory # readList :: ReadS [GeneralCategory] # | |
| Read Word16 | Since: base-2.1 | 
| Read Word32 | Since: base-2.1 | 
| Read Word64 | Since: base-2.1 | 
| Read Word8 | Since: base-2.1 | 
| Read Lexeme | Since: base-2.1 | 
| Read Ordering | Since: base-2.1 | 
| Read Integer | Since: base-2.1 | 
| Read Natural | Since: base-4.8.0.0 | 
| Read () | Since: base-2.1 | 
| Read Bool | Since: base-2.1 | 
| Read Char | Since: base-2.1 | 
| Read Double | Since: base-2.1 | 
| Read Float | Since: base-2.1 | 
| Read Int | Since: base-2.1 | 
| Read Word | Since: base-4.5.0.0 | 
| (Integral a, Read a) => Read (Ratio a) | Since: base-2.1 | 
| Read a => Read (NonEmpty a) | Since: base-4.11.0.0 | 
| Read a => Read (Maybe a) | Since: base-2.1 | 
| Read a => Read (a) | Since: base-4.15 | 
| Read a => Read [a] | Since: base-2.1 | 
| Reifies s (ReadDict a) => Read (AdHoc s a) Source # | |
| (Read a, Read b) => Read (Either a b) | Since: base-3.0 | 
| Read (Proxy t) | Since: base-4.7.0.0 | 
| (Ix a, Read a, Read b) => Read (Array a b) | Since: base-2.1 | 
| (Read a, Read b) => Read (a, b) | Since: base-2.1 | 
| (Read a, Read b, Read c) => Read (a, b, c) | Since: base-2.1 | 
| (Read a, Read b, Read c, Read d) => Read (a, b, c, d) | Since: base-2.1 | 
| (Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e) | Since: base-2.1 | 
| (Read a, Read b, Read c, Read d, Read e, Read f) => Read (a, b, c, d, e, f) | Since: base-2.1 | 
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g) => Read (a, b, c, d, e, f, g) | Since: base-2.1 | 
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h) => Read (a, b, c, d, e, f, g, h) | Since: base-2.1 | 
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i) => Read (a, b, c, d, e, f, g, h, i) | Since: base-2.1 | 
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j) => Read (a, b, c, d, e, f, g, h, i, j) | Since: base-2.1 | 
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k) => Read (a, b, c, d, e, f, g, h, i, j, k) | Since: base-2.1 | 
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l) => Read (a, b, c, d, e, f, g, h, i, j, k, l) | Since: base-2.1 | 
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m) | Since: base-2.1 | 
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m, Read n) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | Since: base-2.1 | 
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m, Read n, Read o) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) | Since: base-2.1 | 
| Defined in GHC.Read | |
class Read1 (f :: Type -> Type) 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:
instanceRead1T whereliftReadPrec= ...liftReadListPrec=liftReadListPrecDefault
For more information, refer to the documentation for the Read class.
Since: base-4.9.0.0
Minimal complete definition
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: base-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: base-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: base-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: base-4.10.0.0
Instances
| Read1 Complex | 
 Since: base-4.16.0.0 | 
| Defined in Data.Functor.Classes | |
| Read1 Identity | Since: base-4.9.0.0 | 
| Defined in Data.Functor.Classes | |
| Read1 Down | Since: base-4.12.0.0 | 
| Defined in Data.Functor.Classes | |
| Read1 NonEmpty | Since: base-4.10.0.0 | 
| Defined in Data.Functor.Classes | |
| Read1 Maybe | Since: base-4.9.0.0 | 
| Defined in Data.Functor.Classes | |
| Read1 Solo | Since: base-4.15 | 
| Defined in Data.Functor.Classes | |
| Read1 [] | Since: base-4.9.0.0 | 
| Defined in Data.Functor.Classes | |
| (forall a. Read a => Read (f a), forall xx yy. Coercible xx yy => Coercible (f xx) (f yy)) => Read1 (Reflected1 f) Source # | |
| Defined in AutoLift Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Reflected1 f a) # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Reflected1 f a] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Reflected1 f a) # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Reflected1 f a] # | |
| Read a => Read1 (Either a) | Since: base-4.9.0.0 | 
| Defined in Data.Functor.Classes Methods liftReadsPrec :: (Int -> ReadS a0) -> ReadS [a0] -> Int -> ReadS (Either a a0) # liftReadList :: (Int -> ReadS a0) -> ReadS [a0] -> ReadS [Either a a0] # liftReadPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec (Either a a0) # liftReadListPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec [Either a a0] # | |
| Read1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 | 
| Defined in Data.Functor.Classes | |
| Read a => Read1 ((,) a) | Since: base-4.9.0.0 | 
| Defined in Data.Functor.Classes | |
| Read a => Read1 (Const a :: Type -> Type) | Since: base-4.9.0.0 | 
| Defined in Data.Functor.Classes Methods liftReadsPrec :: (Int -> ReadS a0) -> ReadS [a0] -> Int -> ReadS (Const a a0) # liftReadList :: (Int -> ReadS a0) -> ReadS [a0] -> ReadS [Const a a0] # liftReadPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec (Const a a0) # liftReadListPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec [Const a a0] # | |
| (Read a, Read b) => Read1 ((,,) a b) | Since: base-4.16.0.0 | 
| Defined in Data.Functor.Classes | |
| (Read a, Read b, Read c) => Read1 ((,,,) a b c) | Since: base-4.16.0.0 | 
| Defined in Data.Functor.Classes Methods liftReadsPrec :: (Int -> ReadS a0) -> ReadS [a0] -> Int -> ReadS (a, b, c, a0) # liftReadList :: (Int -> ReadS a0) -> ReadS [a0] -> ReadS [(a, b, c, a0)] # liftReadPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec (a, b, c, a0) # liftReadListPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec [(a, b, c, a0)] # | |
Instances
| MonadFail ReadPrec | Since: base-4.9.0.0 | 
| Defined in Text.ParserCombinators.ReadPrec | |
| Alternative ReadPrec | Since: base-4.6.0.0 | 
| Applicative ReadPrec | Since: base-4.6.0.0 | 
| Functor ReadPrec | Since: base-2.1 | 
| Monad ReadPrec | Since: base-2.1 | 
| MonadPlus ReadPrec | Since: base-2.1 |