fmt-0.6.3.0: A new formatting library
Safe HaskellNone
LanguageHaskell2010

Fmt.Internal.Generic

Synopsis

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

Instances details
(GBuildable (Rep a), Generic a) => Buildable (GenericBuildable a) Source # 
Instance details

Defined in Fmt.Internal.Generic

class GBuildable f where Source #

Methods

gbuild :: f a -> Builder Source #

Instances

Instances details
Buildable' c => GBuildable (K1 i c :: Type -> Type) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

gbuild :: K1 i c a -> Builder Source #

(GBuildable a, GBuildable b) => GBuildable (a :+: b) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

gbuild :: (a :+: b) a0 -> Builder Source #

GBuildable a => GBuildable (M1 D d a) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

gbuild :: M1 D d a a0 -> Builder Source #

(GetFields a, Constructor c) => GBuildable (M1 C c a) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

gbuild :: M1 C c a a0 -> Builder 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.

Methods

build' :: a -> Builder Source #

Instances

Instances details
Buildable' () Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: () -> Builder Source #

Buildable a => Buildable' a Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: a -> Builder Source #

Buildable' IntSet Source # 
Instance details

Defined in Fmt.Internal.Generic

Buildable' [Char] Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: [Char] -> Builder Source #

Buildable' a => Buildable' [a] Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: [a] -> Builder Source #

Buildable' a => Buildable' (Maybe a) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: Maybe a -> Builder Source #

Buildable' a => Buildable' (NonEmpty a) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: NonEmpty a -> Builder Source #

Buildable' v => Buildable' (IntMap v) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: IntMap v -> Builder Source #

Buildable' a => Buildable' (Seq a) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: Seq a -> Builder Source #

Buildable' v => Buildable' (Set v) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: Set v -> Builder Source #

Buildable' (a -> b) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: (a -> b) -> Builder Source #

(Buildable' a, Buildable' b) => Buildable' (Either a b) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: Either a b -> Builder Source #

(Buildable' a1, Buildable' a2) => Buildable' (a1, a2) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: (a1, a2) -> Builder Source #

(Buildable' k, Buildable' v) => Buildable' (Map k v) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: Map k v -> Builder Source #

(Buildable' a1, Buildable' a2, Buildable' a3) => Buildable' (a1, a2, a3) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: (a1, a2, a3) -> Builder Source #

(Buildable' a1, Buildable' a2, Buildable' a3, Buildable' a4) => Buildable' (a1, a2, a3, a4) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: (a1, a2, a3, a4) -> Builder Source #

(Buildable' a1, Buildable' a2, Buildable' a3, Buildable' a4, Buildable' a5) => Buildable' (a1, a2, a3, a4, a5) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: (a1, a2, a3, a4, a5) -> Builder Source #

(Buildable' a1, Buildable' a2, Buildable' a3, Buildable' a4, Buildable' a5, Buildable' a6) => Buildable' (a1, a2, a3, a4, a5, a6) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: (a1, a2, a3, a4, a5, a6) -> Builder Source #

(Buildable' a1, Buildable' a2, Buildable' a3, Buildable' a4, Buildable' a5, Buildable' a6, Buildable' a7) => Buildable' (a1, a2, a3, a4, a5, a6, a7) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: (a1, a2, a3, a4, a5, a6, a7) -> Builder Source #

(Buildable' a1, Buildable' a2, Buildable' a3, Buildable' a4, Buildable' a5, Buildable' a6, Buildable' a7, Buildable' a8) => Buildable' (a1, a2, a3, a4, a5, a6, a7, a8) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

build' :: (a1, a2, a3, a4, a5, a6, a7, a8) -> Builder Source #

class GetFields f where Source #

Methods

getFields :: f a -> [(String, Builder)] Source #

Get fields, together with their names if available

Instances

Instances details
GetFields (U1 :: Type -> Type) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

getFields :: U1 a -> [(String, Builder)] Source #

(GetFields a, GetFields b) => GetFields (a :*: b) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

getFields :: (a :*: b) a0 -> [(String, Builder)] Source #

GBuildable a => GetFields (M1 D c a) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

getFields :: M1 D c a a0 -> [(String, Builder)] Source #

GBuildable a => GetFields (M1 C c a) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

getFields :: M1 C c a a0 -> [(String, Builder)] Source #

(GBuildable a, Selector c) => GetFields (M1 S c a) Source # 
Instance details

Defined in Fmt.Internal.Generic

Methods

getFields :: M1 S c a a0 -> [(String, Builder)] Source #