| Copyright | (C) 2014-2017 Ryan Scott |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Ryan Scott |
| Stability | Provisional |
| Portability | GHC |
| Safe Haskell | None |
| Language | Haskell2010 |
TextShow.Generic
Contents
Description
Generic versions of TextShow and TextShow1 class functions, as an alternative to
TextShow.TH, which uses Template Haskell. Because there is no Generic2
class, TextShow2 cannot be implemented generically.
This implementation is loosely based off of the Generics.Deriving.Show module
from the generic-deriving library.
Since: 2
- genericShowt :: (Generic a, GTextShowT Zero (Rep a)) => a -> Text
- genericShowtl :: (Generic a, GTextShowTL Zero (Rep a)) => a -> Text
- genericShowtPrec :: (Generic a, GTextShowT Zero (Rep a)) => Int -> a -> Text
- genericShowtlPrec :: (Generic a, GTextShowTL Zero (Rep a)) => Int -> a -> Text
- genericShowtList :: (Generic a, GTextShowT Zero (Rep a)) => [a] -> Text
- genericShowtlList :: (Generic a, GTextShowTL Zero (Rep a)) => [a] -> Text
- genericShowb :: (Generic a, GTextShowB Zero (Rep a)) => a -> Builder
- genericShowbPrec :: (Generic a, GTextShowB Zero (Rep a)) => Int -> a -> Builder
- genericShowbList :: (Generic a, GTextShowB Zero (Rep a)) => [a] -> Builder
- genericPrintT :: (Generic a, GTextShowT Zero (Rep a)) => a -> IO ()
- genericPrintTL :: (Generic a, GTextShowTL Zero (Rep a)) => a -> IO ()
- genericHPrintT :: (Generic a, GTextShowT Zero (Rep a)) => Handle -> a -> IO ()
- genericHPrintTL :: (Generic a, GTextShowTL Zero (Rep a)) => Handle -> a -> IO ()
- genericLiftShowbPrec :: (Generic1 f, GTextShowB One (Rep1 f)) => (Int -> a -> Builder) -> ([a] -> Builder) -> Int -> f a -> Builder
- genericShowbPrec1 :: (Generic a, Generic1 f, GTextShowB Zero (Rep a), GTextShowB One (Rep1 f)) => Int -> f a -> Builder
- class GTextShowB arity f where
- class GTextShowConB arity f where
- data ShowFunsB arity a where
- NoShowFunsB :: ShowFunsB Zero a
- Show1FunsB :: (Int -> a -> Builder) -> ([a] -> Builder) -> ShowFunsB One a
- class GTextShowT arity f where
- class GTextShowConT arity f where
- data ShowFunsT arity a where
- NoShowFunsT :: ShowFunsT Zero a
- Show1FunsT :: (Int -> a -> Text) -> ([a] -> Text) -> ShowFunsT One a
- class GTextShowTL arity f where
- class GTextShowConTL arity f where
- data ShowFunsTL arity a where
- NoShowFunsTL :: ShowFunsTL Zero a
- Show1FunsTL :: (Int -> a -> Text) -> ([a] -> Text) -> ShowFunsTL One a
- class IsNullary f where
- data ConType
- data Zero
- data One
Generic show functions
TextShow instances can be easily defined for data types that are Generic instances.
The easiest way to do this is to use the DeriveGeneric extension.
{-# LANGUAGE DeriveGeneric #-}
import GHC.Generics
import TextShow
import TextShow.Generic
data D a = D a
deriving (Generic, Generic1)
instance TextShow a => TextShow (D a) where
showbPrec = genericShowbPrec
instance TextShow1 D where
liftShowbPrec = genericLiftShowbPrec
Understanding a compiler error
Suppose you intend to use genericShowbPrec to define a TextShow instance.
data Oops = Oops
-- forgot to add "deriving Generic" here!
instance TextShow Oops where
showbPrec = genericShowbPrec
If you forget to add a deriving clause to your data type, at
compile-time, you might get an error message that begins roughly as follows:Generic
No instance for (GTextShowBZero(Rep Oops))
This error can be confusing, but don't let it intimidate you. The correct fix is
simply to add the missing "deriving " clause.Generic
Similarly, if the compiler complains about not having an instance for (, add a "GTextShowB
One (Rep1 Oops1))deriving " clause.Generic1
genericShowt :: (Generic a, GTextShowT Zero (Rep a)) => a -> Text Source #
genericShowtl :: (Generic a, GTextShowTL Zero (Rep a)) => a -> Text Source #
genericShowtPrec :: (Generic a, GTextShowT Zero (Rep a)) => Int -> a -> Text Source #
A Generic implementation of showPrect.
Since: 2
genericShowtlPrec :: (Generic a, GTextShowTL Zero (Rep a)) => Int -> a -> Text Source #
A Generic implementation of showtlPrec.
Since: 2
genericShowtList :: (Generic a, GTextShowT Zero (Rep a)) => [a] -> Text Source #
genericShowtlList :: (Generic a, GTextShowTL Zero (Rep a)) => [a] -> Text Source #
A Generic implementation of showtlList.
Since: 2
genericShowb :: (Generic a, GTextShowB Zero (Rep a)) => a -> Builder Source #
genericShowbPrec :: (Generic a, GTextShowB Zero (Rep a)) => Int -> a -> Builder Source #
genericShowbList :: (Generic a, GTextShowB Zero (Rep a)) => [a] -> Builder Source #
genericPrintT :: (Generic a, GTextShowT Zero (Rep a)) => a -> IO () Source #
A Generic implementation of printT.
Since: 2
genericPrintTL :: (Generic a, GTextShowTL Zero (Rep a)) => a -> IO () Source #
A Generic implementation of printTL.
Since: 2
genericHPrintT :: (Generic a, GTextShowT Zero (Rep a)) => Handle -> a -> IO () Source #
A Generic implementation of hPrintT.
Since: 2
genericHPrintTL :: (Generic a, GTextShowTL Zero (Rep a)) => Handle -> a -> IO () Source #
A Generic implementation of hPrintTL.
Since: 2
genericLiftShowbPrec :: (Generic1 f, GTextShowB One (Rep1 f)) => (Int -> a -> Builder) -> ([a] -> Builder) -> Int -> f a -> Builder Source #
A Generic1 implementation of genericLiftShowbPrec.
Since: 2
genericShowbPrec1 :: (Generic a, Generic1 f, GTextShowB Zero (Rep a), GTextShowB One (Rep1 f)) => Int -> f a -> Builder Source #
A 'Generic'/'Generic1' implementation of showbPrec1.
Since: 2
Internals
Builder
class GTextShowB arity f where Source #
Class of generic representation types that can be converted to a Builder. The arity type variable indicates which type class is used. indicates GTextShowB ZeroTextShow behavior, and indicates GTextShowB OneTextShow1 behavior. Since: 3.4
Minimal complete definition
Methods
gShowbPrec :: ShowFunsB arity a -> Int -> f a -> Builder Source #
This is used as the default generic implementation of showbPrec (if the arity is Zero) or liftShowbPrec (if the arity is One).
Instances
| GTextShowB One V1 Source # | |
| GTextShowB Zero V1 Source # | |
| (Constructor Meta c, GTextShowConB arity f, IsNullary * f) => GTextShowB arity (C1 c f) Source # | |
| (GTextShowB arity f, GTextShowB arity g) => GTextShowB arity ((:+:) f g) Source # | |
| GTextShowB arity f => GTextShowB arity (D1 d f) Source # | |
class GTextShowConB arity f where Source #
Class of generic representation types for which the ConType has been determined. The arity type variable indicates which type class is used. indicates GTextShowConB ZeroTextShow behavior, and indicates GTextShowConB OneTextShow1 behavior.
Minimal complete definition
Instances
| GTextShowConB arity UWord Source # | |
| GTextShowConB arity UInt Source # | |
| GTextShowConB arity UFloat Source # | |
| GTextShowConB arity UDouble Source # | |
| GTextShowConB arity UChar Source # | |
| GTextShowConB arity U1 Source # | |
| GTextShowConB One Par1 Source # | |
| TextShow1 f => GTextShowConB One (Rec1 f) Source # | |
| (GTextShowConB arity f, GTextShowConB arity g) => GTextShowConB arity ((:*:) f g) Source # | |
| (Selector Meta s, GTextShowConB arity f) => GTextShowConB arity (S1 s f) Source # | |
| TextShow c => GTextShowConB arity (K1 i c) Source # | |
| (TextShow1 f, GTextShowConB One g) => GTextShowConB One ((:.:) f g) Source # | |
data ShowFunsB arity a where Source #
A ShowFunsB value either stores nothing (for TextShow) or it stores the two function arguments that show occurrences of the type parameter (for TextShow1). Since: 3.4
Constructors
| NoShowFunsB :: ShowFunsB Zero a | |
| Show1FunsB :: (Int -> a -> Builder) -> ([a] -> Builder) -> ShowFunsB One a |
Instances
| Contravariant (ShowFunsB arity) Source # | |
Strict Text
class GTextShowT arity f where Source #
Class of generic representation types that can be converted to a Text. The arity type variable indicates which type class is used. indicates GTextShowT ZeroTextShow behavior, and indicates GTextShowT OneTextShow1 behavior. Since: 3.4
Minimal complete definition
Methods
gShowtPrec :: ShowFunsT arity a -> Int -> f a -> Text Source #
This is used as the default generic implementation of showtPrec (if the arity is Zero) or liftShowtPrec (if the arity is One).
Instances
| GTextShowT One V1 Source # | |
| GTextShowT Zero V1 Source # | |
| (Constructor Meta c, GTextShowConT arity f, IsNullary * f) => GTextShowT arity (C1 c f) Source # | |
| (GTextShowT arity f, GTextShowT arity g) => GTextShowT arity ((:+:) f g) Source # | |
| GTextShowT arity f => GTextShowT arity (D1 d f) Source # | |
class GTextShowConT arity f where Source #
Class of generic representation types for which the ConType has been determined. The arity type variable indicates which type class is used. indicates GTextShowConT ZeroTextShow behavior, and indicates GTextShowConT OneTextShow1 behavior.
Minimal complete definition
Instances
| GTextShowConT arity UWord Source # | |
| GTextShowConT arity UInt Source # | |
| GTextShowConT arity UFloat Source # | |
| GTextShowConT arity UDouble Source # | |
| GTextShowConT arity UChar Source # | |
| GTextShowConT arity U1 Source # | |
| GTextShowConT One Par1 Source # | |
| TextShow1 f => GTextShowConT One (Rec1 f) Source # | |
| (GTextShowConT arity f, GTextShowConT arity g) => GTextShowConT arity ((:*:) f g) Source # | |
| (Selector Meta s, GTextShowConT arity f) => GTextShowConT arity (S1 s f) Source # | |
| TextShow c => GTextShowConT arity (K1 i c) Source # | |
| (TextShow1 f, GTextShowConT One g) => GTextShowConT One ((:.:) f g) Source # | |
data ShowFunsT arity a where Source #
A ShowFunsT value either stores nothing (for TextShow) or it stores the two function arguments that show occurrences of the type parameter (for TextShow1). Since: 3.4
Constructors
| NoShowFunsT :: ShowFunsT Zero a | |
| Show1FunsT :: (Int -> a -> Text) -> ([a] -> Text) -> ShowFunsT One a |
Instances
| Contravariant (ShowFunsT arity) Source # | |
Lazy Text
class GTextShowTL arity f where Source #
Class of generic representation types that can be converted to a Text. The arity type variable indicates which type class is used. indicates GTextShowTL ZeroTextShow behavior, and indicates GTextShowTL OneTextShow1 behavior. Since: 3.4
Minimal complete definition
Methods
gShowtlPrec :: ShowFunsTL arity a -> Int -> f a -> Text Source #
This is used as the default generic implementation of showtlPrec (if the arity is Zero) or liftShowtlPrec (if the arity is One).
Instances
| GTextShowTL One V1 Source # | |
| GTextShowTL Zero V1 Source # | |
| (Constructor Meta c, GTextShowConTL arity f, IsNullary * f) => GTextShowTL arity (C1 c f) Source # | |
| (GTextShowTL arity f, GTextShowTL arity g) => GTextShowTL arity ((:+:) f g) Source # | |
| GTextShowTL arity f => GTextShowTL arity (D1 d f) Source # | |
class GTextShowConTL arity f where Source #
Class of generic representation types for which the ConType has been determined. The arity type variable indicates which type class is used. indicates GTextShowConTL ZeroTextShow behavior, and indicates GTextShowConTL OneTextShow1 behavior.
Minimal complete definition
Methods
gShowtlPrecCon :: ConType -> ShowFunsTL arity a -> Int -> f a -> Text Source #
Instances
| GTextShowConTL arity UWord Source # | |
| GTextShowConTL arity UInt Source # | |
| GTextShowConTL arity UFloat Source # | |
| GTextShowConTL arity UDouble Source # | |
| GTextShowConTL arity UChar Source # | |
| GTextShowConTL arity U1 Source # | |
| GTextShowConTL One Par1 Source # | |
| TextShow1 f => GTextShowConTL One (Rec1 f) Source # | |
| (GTextShowConTL arity f, GTextShowConTL arity g) => GTextShowConTL arity ((:*:) f g) Source # | |
| (Selector Meta s, GTextShowConTL arity f) => GTextShowConTL arity (S1 s f) Source # | |
| TextShow c => GTextShowConTL arity (K1 i c) Source # | |
| (TextShow1 f, GTextShowConTL One g) => GTextShowConTL One ((:.:) f g) Source # | |
data ShowFunsTL arity a where Source #
A ShowFunsTL value either stores nothing (for TextShow) or it stores the two function arguments that show occurrences of the type parameter (for TextShow1). Since: 3.4
Constructors
| NoShowFunsTL :: ShowFunsTL Zero a | |
| Show1FunsTL :: (Int -> a -> Text) -> ([a] -> Text) -> ShowFunsTL One a |
Instances
| Contravariant (ShowFunsTL arity) Source # | |
Other internals
class IsNullary f where Source #
Class of generic representation types that represent a constructor with zero or more fields.
Minimal complete definition
Instances
| IsNullary * U1 Source # | |
| IsNullary * UChar Source # | |
| IsNullary * UDouble Source # | |
| IsNullary * UFloat Source # | |
| IsNullary * UInt Source # | |
| IsNullary * UWord Source # | |
| IsNullary * (Rec1 f) Source # | |
| IsNullary * (K1 i c) Source # | |
| IsNullary * ((:*:) f g) Source # | |
| IsNullary * ((:.:) f g) Source # | |
| IsNullary * f => IsNullary * (S1 s f) Source # | |
| IsNullary * Par1 Source # | |
A type-level indicator that TextShow is being derived generically.
Since: 3.2
Instances
A type-level indicator that TextShow1 is being derived generically.
Since: 3.2
Instances
| GTextShowConTL One Par1 Source # | |
| GTextShowTL One V1 Source # | |
| GTextShowConT One Par1 Source # | |
| GTextShowT One V1 Source # | |
| GTextShowConB One Par1 Source # | |
| GTextShowB One V1 Source # | |
| TextShow1 f => GTextShowConTL One (Rec1 f) Source # | |
| TextShow1 f => GTextShowConT One (Rec1 f) Source # | |
| TextShow1 f => GTextShowConB One (Rec1 f) Source # | |
| (TextShow1 f, GTextShowConTL One g) => GTextShowConTL One ((:.:) f g) Source # | |
| (TextShow1 f, GTextShowConT One g) => GTextShowConT One ((:.:) f g) Source # | |
| (TextShow1 f, GTextShowConB One g) => GTextShowConB One ((:.:) f g) Source # | |