| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Fmt.Internal.Generic
Synopsis
- genericF :: (Generic a, GBuildable (Rep a)) => a -> Builder
- newtype GenericBuildable a = GenericBuildable a
- class GBuildable f where
- class Buildable' a where
- class GetFields f where
Documentation
>>>import Fmt
genericF :: (Generic a, GBuildable (Rep a)) => a -> Builder Source #
Format an arbitrary value without requiring a Buildable instance:
>>>data Foo = Foo { x :: Bool, y :: [Int] } deriving Generic
>>>fmt (genericF (Foo True [1,2,3]))Foo: x: True y: [1, 2, 3]
It works for non-record constructors too:
>>>data Bar = Bar Bool [Int] deriving Generic
>>>fmtLn (genericF (Bar True [1,2,3]))<Bar: True, [1, 2, 3]>
Any fields inside the type must either be Buildable or one of the following
types:
The exact format of genericF might change in future versions, so don't rely
on it. It's merely a convenience function.
newtype GenericBuildable a Source #
A newtype for deriving a generic Buildable instance for any type
using DerivingVia.
>>>:set -XDerivingVia>>>:{data Bar = Bar { x :: Bool, y :: [Int] } deriving stock Generic deriving Buildable via GenericBuildable Bar :}
>>>pretty (Bar True [1,2,3])Bar: x: True y: [1, 2, 3]
Constructors
| GenericBuildable a |
Instances
| (GBuildable (Rep a), Generic a) => Buildable (GenericBuildable a) Source # | |
Defined in Fmt.Internal.Generic Methods build :: GenericBuildable a -> Builder # | |
class GBuildable f where Source #
Instances
| Buildable' c => GBuildable (K1 i c :: Type -> Type) Source # | |
| (GBuildable a, GBuildable b) => GBuildable (a :+: b) Source # | |
| GBuildable a => GBuildable (M1 D d a) Source # | |
| (GetFields a, Constructor c) => GBuildable (M1 C c a) Source # | |
class Buildable' a where Source #
A more powerful Buildable used for genericF. Can build functions,
tuples, lists, maps, etc., as well as combinations thereof.
Instances
class GetFields f where Source #
Methods
getFields :: f a -> [(String, Builder)] Source #
Get fields, together with their names if available