| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
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
- newtype Fmt m a b = Fmt {
- unFmt :: (m -> a) -> b
- runFmt :: Fmt m m a -> a
- type Fmt1 m s a = Fmt m s (a -> s)
- type Fmt2 m s a b = Fmt m s (a -> b -> s)
- type Fmt3 m s a b c = Fmt m s (a -> b -> c -> s)
- fmt1 :: (a -> m) -> Fmt1 m s a
- fmt2 :: (a -> b -> m) -> Fmt2 m s a b
- fmt1_ :: Fmt m a a -> Fmt1 m a b
- fmt2_ :: Fmt m a a -> Fmt2 m a b c
- (.%) :: Semigroup m => Fmt1 m s a -> Fmt1 m s a -> Fmt1 m s a
- cat1 :: (Monoid m, Foldable f) => Fmt1 m m a -> Fmt1 m s (f a)
- fmt :: m -> Fmt m a a
- (%) :: Semigroup m => Fmt m b c -> Fmt m a b -> Fmt m a c
- apply :: Fmt1 m s m -> Fmt m s a -> Fmt m s a
- bind :: Fmt m a1 b -> (m -> Fmt m a2 a1) -> Fmt m a2 b
- cat :: (Monoid m, Foldable f) => f (Fmt m a a) -> Fmt m a a
- refmt :: (m1 -> m2) -> Fmt m1 a b -> Fmt m2 a b
- prefix :: Semigroup m => m -> Fmt m a b -> Fmt m a b
- suffix :: Semigroup m => m -> Fmt m a b -> Fmt m a b
- enclose :: Semigroup m => Fmt m b2 c -> Fmt m a b1 -> Fmt m b1 b2 -> Fmt m a c
- tuple :: (Semigroup m, IsString m) => Fmt m b c -> Fmt m a b -> Fmt m a c
- quotes :: (Semigroup m, IsString m) => Fmt m a b -> Fmt m a b
- quotes' :: (Semigroup m, IsString m) => Fmt m a b -> Fmt m a b
- parens :: (Semigroup m, IsString m) => Fmt m a b -> Fmt m a b
- braces :: (Semigroup m, IsString m) => Fmt m a b -> Fmt m a b
- brackets :: (Semigroup m, IsString m) => Fmt m a b -> Fmt m a b
- backticks :: (Semigroup m, IsString m) => Fmt m a b -> Fmt m a b
- indent :: (IsString m, Semigroup m) => Int -> Fmt m a b -> Fmt m a b
- left1 :: IsString m => Fmt1 m m a -> Fmt1 m s (Either a b)
- right1 :: IsString m => Fmt1 m m b -> Fmt1 m s (Either a b)
- either1 :: Fmt1 m m a -> Fmt1 m m b -> Fmt1 m s (Either a b)
- maybe1 :: m -> Fmt1 m m a -> Fmt1 m s (Maybe a)
Type
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.
Instances
| Monoid m => Category (Fmt m :: Type -> Type -> Type) Source # | |
| Monoid m => Arrow (Fmt m) Source # | |
| Cochoice (Fmt m) Source # | |
| Closed (Fmt m) Source # | |
| Corepresentable (Fmt m) Source # | |
| Costrong (Fmt m) Source # | |
| Monoid m => Strong (Fmt m) Source # | |
| Profunctor (Fmt m) Source # | |
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 # | |
Defined in Data.Fmt.Type | |
| Applicative (Fmt m a) Source # | |
| Functor (Fmt m a) Source # | |
| Monad (Fmt m a) Source # | |
| (IsString m, a ~ b) => IsString (Fmt m a b) Source # | |
Defined in Data.Fmt.Type Methods fromString :: String -> Fmt m a b # | |
| Monoid m => Monoid (Fmt1 m s a) Source # | |
| Semigroup m => Semigroup (Fmt1 m s a) Source # | |
| type Corep (Fmt m) Source # | |
Defined in Data.Fmt.Type | |
Fmt1 / Fmt2
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
(.%) :: 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
(%) :: Semigroup m => Fmt m b c -> Fmt m a b -> Fmt m a c infixr 0 Source #
Concatenate two formatters.
cat :: (Monoid m, Foldable f) => f (Fmt m a a) -> Fmt m a a Source #
Concatenate a collection of formatters.
Formatting
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.
Collections
left1 :: IsString m => Fmt1 m m a -> Fmt1 m s (Either a b) Source #
Format a Left, rendering Right as empty.