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 (GTextShowB
Zero
(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 #
genericShowtl :: (Generic a, GTextShowTL Zero (Rep a)) => a -> Text #
genericShowtPrec :: (Generic a, GTextShowT Zero (Rep a)) => Int -> a -> Text #
A Generic
implementation of showPrect
.
Since: 2
genericShowtlPrec :: (Generic a, GTextShowTL Zero (Rep a)) => Int -> a -> Text #
A Generic
implementation of showtlPrec
.
Since: 2
genericShowtList :: (Generic a, GTextShowT Zero (Rep a)) => [a] -> Text #
genericShowtlList :: (Generic a, GTextShowTL Zero (Rep a)) => [a] -> Text #
A Generic
implementation of showtlList
.
Since: 2
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 () #
A Generic
implementation of printT
.
Since: 2
genericPrintTL :: (Generic a, GTextShowTL Zero (Rep a)) => a -> IO () #
A Generic
implementation of printTL
.
Since: 2
genericHPrintT :: (Generic a, GTextShowT Zero (Rep a)) => Handle -> a -> IO () #
A Generic
implementation of hPrintT
.
Since: 2
genericHPrintTL :: (Generic a, GTextShowTL Zero (Rep a)) => Handle -> a -> IO () #
A Generic
implementation of hPrintTL
.
Since: 2
genericLiftShowbPrec :: (Generic1 f, GTextShowB One (Rep1 f)) => (Int -> a -> Builder) -> ([a] -> Builder) -> Int -> f a -> Builder #
A Generic1
implementation of genericLiftShowbPrec
.
Since: 2
genericShowbPrec1 :: (Generic a, Generic1 f, GTextShowB Zero (Rep a), GTextShowB One (Rep1 f)) => Int -> f a -> Builder #
A 'Generic'/'Generic1' implementation of showbPrec1
.
Since: 2
Internals
Builder
class GTextShowB arity f where #
Class of generic representation types that can be converted to a Builder
. The arity
type variable indicates which type class is used.
indicates GTextShowB
Zero
TextShow
behavior, and
indicates GTextShowB
One
TextShow1
behavior. Since: 3.4
Minimal complete definition
Methods
gShowbPrec :: ShowFunsB arity a -> Int -> f a -> Builder #
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 # | |
GTextShowB Zero V1 # | |
(Constructor Meta c, GTextShowConB arity f, IsNullary * f) => GTextShowB arity (C1 c f) # | |
(GTextShowB arity f, GTextShowB arity g) => GTextShowB arity ((:+:) f g) # | |
GTextShowB arity f => GTextShowB arity (D1 d f) # | |
class GTextShowConB arity f where #
Class of generic representation types for which the ConType
has been determined. The arity
type variable indicates which type class is used.
indicates GTextShowConB
Zero
TextShow
behavior, and
indicates GTextShowConB
One
TextShow1
behavior.
Minimal complete definition
Instances
GTextShowConB arity UWord # | |
GTextShowConB arity UInt # | |
GTextShowConB arity UFloat # | |
GTextShowConB arity UDouble # | |
GTextShowConB arity UChar # | |
GTextShowConB arity U1 # | |
GTextShowConB One Par1 # | |
TextShow1 f => GTextShowConB One (Rec1 f) # | |
(GTextShowConB arity f, GTextShowConB arity g) => GTextShowConB arity ((:*:) f g) # | |
(Selector Meta s, GTextShowConB arity f) => GTextShowConB arity (S1 s f) # | |
TextShow c => GTextShowConB arity (K1 i c) # | |
(TextShow1 f, GTextShowConB One g) => GTextShowConB One ((:.:) f g) # | |
data ShowFunsB arity a where #
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) # | |
Strict Text
class GTextShowT arity f where #
Class of generic representation types that can be converted to a Text
. The arity
type variable indicates which type class is used.
indicates GTextShowT
Zero
TextShow
behavior, and
indicates GTextShowT
One
TextShow1
behavior. Since: 3.4
Minimal complete definition
Methods
gShowtPrec :: ShowFunsT arity a -> Int -> f a -> Text #
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 # | |
GTextShowT Zero V1 # | |
(Constructor Meta c, GTextShowConT arity f, IsNullary * f) => GTextShowT arity (C1 c f) # | |
(GTextShowT arity f, GTextShowT arity g) => GTextShowT arity ((:+:) f g) # | |
GTextShowT arity f => GTextShowT arity (D1 d f) # | |
class GTextShowConT arity f where #
Class of generic representation types for which the ConType
has been determined. The arity
type variable indicates which type class is used.
indicates GTextShowConT
Zero
TextShow
behavior, and
indicates GTextShowConT
One
TextShow1
behavior.
Minimal complete definition
Instances
GTextShowConT arity UWord # | |
GTextShowConT arity UInt # | |
GTextShowConT arity UFloat # | |
GTextShowConT arity UDouble # | |
GTextShowConT arity UChar # | |
GTextShowConT arity U1 # | |
GTextShowConT One Par1 # | |
TextShow1 f => GTextShowConT One (Rec1 f) # | |
(GTextShowConT arity f, GTextShowConT arity g) => GTextShowConT arity ((:*:) f g) # | |
(Selector Meta s, GTextShowConT arity f) => GTextShowConT arity (S1 s f) # | |
TextShow c => GTextShowConT arity (K1 i c) # | |
(TextShow1 f, GTextShowConT One g) => GTextShowConT One ((:.:) f g) # | |
data ShowFunsT arity a where #
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) # | |
Lazy Text
class GTextShowTL arity f where #
Class of generic representation types that can be converted to a Text
. The arity
type variable indicates which type class is used.
indicates GTextShowTL
Zero
TextShow
behavior, and
indicates GTextShowTL
One
TextShow1
behavior. Since: 3.4
Minimal complete definition
Methods
gShowtlPrec :: ShowFunsTL arity a -> Int -> f a -> Text #
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 # | |
GTextShowTL Zero V1 # | |
(Constructor Meta c, GTextShowConTL arity f, IsNullary * f) => GTextShowTL arity (C1 c f) # | |
(GTextShowTL arity f, GTextShowTL arity g) => GTextShowTL arity ((:+:) f g) # | |
GTextShowTL arity f => GTextShowTL arity (D1 d f) # | |
class GTextShowConTL arity f where #
Class of generic representation types for which the ConType
has been determined. The arity
type variable indicates which type class is used.
indicates GTextShowConTL
Zero
TextShow
behavior, and
indicates GTextShowConTL
One
TextShow1
behavior.
Minimal complete definition
Methods
gShowtlPrecCon :: ConType -> ShowFunsTL arity a -> Int -> f a -> Text #
Instances
GTextShowConTL arity UWord # | |
GTextShowConTL arity UInt # | |
GTextShowConTL arity UFloat # | |
GTextShowConTL arity UDouble # | |
GTextShowConTL arity UChar # | |
GTextShowConTL arity U1 # | |
GTextShowConTL One Par1 # | |
TextShow1 f => GTextShowConTL One (Rec1 f) # | |
(GTextShowConTL arity f, GTextShowConTL arity g) => GTextShowConTL arity ((:*:) f g) # | |
(Selector Meta s, GTextShowConTL arity f) => GTextShowConTL arity (S1 s f) # | |
TextShow c => GTextShowConTL arity (K1 i c) # | |
(TextShow1 f, GTextShowConTL One g) => GTextShowConTL One ((:.:) f g) # | |
data ShowFunsTL arity a where #
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) # | |
Other internals
Class of generic representation types that represent a constructor with zero or more fields.
Minimal complete definition
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 # | |
GTextShowTL One V1 # | |
GTextShowConT One Par1 # | |
GTextShowT One V1 # | |
GTextShowConB One Par1 # | |
GTextShowB One V1 # | |
TextShow1 f => GTextShowConTL One (Rec1 f) # | |
TextShow1 f => GTextShowConT One (Rec1 f) # | |
TextShow1 f => GTextShowConB One (Rec1 f) # | |
(TextShow1 f, GTextShowConTL One g) => GTextShowConTL One ((:.:) f g) # | |
(TextShow1 f, GTextShowConT One g) => GTextShowConT One ((:.:) f g) # | |
(TextShow1 f, GTextShowConB One g) => GTextShowConB One ((:.:) f g) # | |