stringfmt
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Fmt.Type

Description

Type-safe formatting as an indexed continuation profunctor.

Fmt m a b = (m -> a) -> b is Costar ((->) m), giving it Category, Arrow, and profunctor instances for free.

person :: Fmt2 String String Int
person = "Person's name is " % t % ", age is " % d

runFmt person Anne 22
-- "Person's name is Anne, age is 22"
Synopsis

Type

newtype Fmt m a b Source #

An indexed continuation formatter.

Fmt m a b = (m -> a) -> b — the monoid m accumulates formatted output, a is the result type, and b captures the arguments.

This is Costar ((->) m) from profunctors, giving Profunctor, Closed, Costrong, Cochoice, Category, and Arrow instances.

Constructors

Fmt 

Fields

Instances

Instances details
Monoid m => Category (Fmt m :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Fmt.Type

Methods

id :: forall (a :: k). Fmt m a a #

(.) :: forall (b :: k) (c :: k) (a :: k). Fmt m b c -> Fmt m a b -> Fmt m a c #

Monoid m => Arrow (Fmt m) Source # 
Instance details

Defined in Data.Fmt.Type

Methods

arr :: (b -> c) -> Fmt m b c #

first :: Fmt m b c -> Fmt m (b, d) (c, d) #

second :: Fmt m b c -> Fmt m (d, b) (d, c) #

(***) :: Fmt m b c -> Fmt m b' c' -> Fmt m (b, b') (c, c') #

(&&&) :: Fmt m b c -> Fmt m b c' -> Fmt m b (c, c') #

Cochoice (Fmt m) Source # 
Instance details

Defined in Data.Fmt.Type

Methods

unleft :: Fmt m (Either a d) (Either b d) -> Fmt m a b Source #

unright :: Fmt m (Either d a) (Either d b) -> Fmt m a b Source #

Closed (Fmt m) Source # 
Instance details

Defined in Data.Fmt.Type

Methods

closed :: Fmt m a b -> Fmt m (x -> a) (x -> b) Source #

Corepresentable (Fmt m) Source # 
Instance details

Defined in Data.Fmt.Type

Associated Types

type Corep (Fmt m) :: Type -> Type Source #

Methods

cotabulate :: (Corep (Fmt m) d -> c) -> Fmt m d c Source #

Costrong (Fmt m) Source # 
Instance details

Defined in Data.Fmt.Type

Methods

unfirst :: Fmt m (a, d) (b, d) -> Fmt m a b Source #

unsecond :: Fmt m (d, a) (d, b) -> Fmt m a b Source #

Monoid m => Strong (Fmt m) Source # 
Instance details

Defined in Data.Fmt.Type

Methods

first' :: Fmt m a b -> Fmt m (a, c) (b, c) Source #

second' :: Fmt m a b -> Fmt m (c, a) (c, b) Source #

Profunctor (Fmt m) Source # 
Instance details

Defined in Data.Fmt.Type

Methods

dimap :: (a -> b) -> (c -> d) -> Fmt m b c -> Fmt m a d Source #

lmap :: (a -> b) -> Fmt m b c -> Fmt m a c Source #

rmap :: (b -> c) -> Fmt m a b -> Fmt m a c Source #

(#.) :: forall a b c q. Coercible c b => q b c -> Fmt m a b -> Fmt m a c Source #

(.#) :: forall a b c q. Coercible b a => Fmt m b c -> q a b -> Fmt m a c Source #

Cosieve (Fmt m) ((->) m) Source # 
Instance details

Defined in Data.Fmt.Type

Methods

cosieve :: Fmt m a b -> (m -> a) -> b Source #

Applicative (Fmt m a) Source # 
Instance details

Defined in Data.Fmt.Type

Methods

pure :: a0 -> Fmt m a a0 #

(<*>) :: Fmt m a (a0 -> b) -> Fmt m a a0 -> Fmt m a b #

liftA2 :: (a0 -> b -> c) -> Fmt m a a0 -> Fmt m a b -> Fmt m a c #

(*>) :: Fmt m a a0 -> Fmt m a b -> Fmt m a b #

(<*) :: Fmt m a a0 -> Fmt m a b -> Fmt m a a0 #

Functor (Fmt m a) Source # 
Instance details

Defined in Data.Fmt.Type

Methods

fmap :: (a0 -> b) -> Fmt m a a0 -> Fmt m a b #

(<$) :: a0 -> Fmt m a b -> Fmt m a a0 #

Monad (Fmt m a) Source # 
Instance details

Defined in Data.Fmt.Type

Methods

(>>=) :: Fmt m a a0 -> (a0 -> Fmt m a b) -> Fmt m a b #

(>>) :: Fmt m a a0 -> Fmt m a b -> Fmt m a b #

return :: a0 -> Fmt m a a0 #

(IsString m, a ~ b) => IsString (Fmt m a b) Source # 
Instance details

Defined in Data.Fmt.Type

Methods

fromString :: String -> Fmt m a b #

Monoid m => Monoid (Fmt1 m s a) Source # 
Instance details

Defined in Data.Fmt.Type

Methods

mempty :: Fmt1 m s a #

mappend :: Fmt1 m s a -> Fmt1 m s a -> Fmt1 m s a #

mconcat :: [Fmt1 m s a] -> Fmt1 m s a #

Semigroup m => Semigroup (Fmt1 m s a) Source # 
Instance details

Defined in Data.Fmt.Type

Methods

(<>) :: Fmt1 m s a -> Fmt1 m s a -> Fmt1 m s a #

sconcat :: NonEmpty (Fmt1 m s a) -> Fmt1 m s a #

stimes :: Integral b => b -> Fmt1 m s a -> Fmt1 m s a #

type Corep (Fmt m) Source # 
Instance details

Defined in Data.Fmt.Type

type Corep (Fmt m) = (->) m

runFmt :: Fmt m m a -> a Source #

Run a Fmt.

Fmt1 / Fmt2

type Fmt1 m s a = Fmt m s (a -> s) Source #

A unary formatter: Fmt1 m s a ~ (m -> s) -> a -> s

type Fmt2 m s a b = Fmt m s (a -> b -> s) Source #

A binary formatter: Fmt2 m s a b ~ (m -> s) -> a -> b -> s

type Fmt3 m s a b c = Fmt m s (a -> b -> c -> s) Source #

A ternary formatter.

fmt1 :: (a -> m) -> Fmt1 m s a Source #

Format a value using a function a -> m.

fmt2 :: (a -> b -> m) -> Fmt2 m s a b Source #

Format two values.

fmt1_ :: Fmt m a a -> Fmt1 m a b Source #

Ignore the input, use a constant formatter.

fmt2_ :: Fmt m a a -> Fmt2 m a b c Source #

Ignore two inputs.

(.%) :: Semigroup m => Fmt1 m s a -> Fmt1 m s a -> Fmt1 m s a infixr 6 Source #

Concatenate two formatters, applying both to the same input.

cat1 :: (Monoid m, Foldable f) => Fmt1 m m a -> Fmt1 m s (f a) Source #

Format each value and concatenate.

Construction

fmt :: m -> Fmt m a a Source #

Format a constant value.

(%) :: Semigroup m => Fmt m b c -> Fmt m a b -> Fmt m a c infixr 0 Source #

Concatenate two formatters.

apply :: Fmt1 m s m -> Fmt m s a -> Fmt m s a Source #

Apply a Fmt1 to a Fmt.

bind :: Fmt m a1 b -> (m -> Fmt m a2 a1) -> Fmt m a2 b Source #

Indexed bind.

cat :: (Monoid m, Foldable f) => f (Fmt m a a) -> Fmt m a a Source #

Concatenate a collection of formatters.

refmt :: (m1 -> m2) -> Fmt m1 a b -> Fmt m2 a b Source #

Map over the formatting monoid.

Formatting

prefix :: Semigroup m => m -> Fmt m a b -> Fmt m a b Source #

Add the given prefix.

suffix :: Semigroup m => m -> Fmt m a b -> Fmt m a b Source #

Add the given suffix.

enclose :: Semigroup m => Fmt m b2 c -> Fmt m a b1 -> Fmt m b1 b2 -> Fmt m a c Source #

Enclose with prefix and suffix.

tuple :: (Semigroup m, IsString m) => Fmt m b c -> Fmt m a b -> Fmt m a c Source #

Format a pair in parentheses.

quotes :: (Semigroup m, IsString m) => Fmt m a b -> Fmt m a b Source #

Double quotes.

quotes' :: (Semigroup m, IsString m) => Fmt m a b -> Fmt m a b Source #

Single quotes.

parens :: (Semigroup m, IsString m) => Fmt m a b -> Fmt m a b Source #

Parentheses.

braces :: (Semigroup m, IsString m) => Fmt m a b -> Fmt m a b Source #

Braces.

brackets :: (Semigroup m, IsString m) => Fmt m a b -> Fmt m a b Source #

Square brackets.

backticks :: (Semigroup m, IsString m) => Fmt m a b -> Fmt m a b Source #

Backticks.

indent :: (IsString m, Semigroup m) => Int -> Fmt m a b -> Fmt m a b Source #

Indent by n spaces.

Collections

left1 :: IsString m => Fmt1 m m a -> Fmt1 m s (Either a b) Source #

Format a Left, rendering Right as empty.

right1 :: IsString m => Fmt1 m m b -> Fmt1 m s (Either a b) Source #

Format a Right, rendering Left as empty.

either1 :: Fmt1 m m a -> Fmt1 m m b -> Fmt1 m s (Either a b) Source #

Format an Either.

maybe1 :: m -> Fmt1 m m a -> Fmt1 m s (Maybe a) Source #

Format a Maybe with a default.