Safe Haskell | None |
---|---|
Language | Haskell2010 |
You want to add formatting support for your custom type. This is the right module.
In PyF, formatters are in three categories:
- Integral numbers, which are numbers without fractional part
- Fractional numbers, which are numbers with a fractional part
- String, which represents text.
The formatting can be either explicit or implicit. For example:
>>>
let x = 10 in [fmt|{x}|]
10
Is an implicit formatting to number, but:
>>>
let x = 10 in [fmt|{x:d}|]
Is an explicit formatting to Integral numbers, using d
.
Implicit formatting will only format to either Integral, Fractional or text,
and this choice is done by the (open) type family PyFCategory
.
This modules also provides 3 type class for formatting.
PyfFormatFractional
andPyfFormatIntegral
are responsible for formatting integral and fractional numbers. Default instances are provided respectively forReal
andIntegral
.PyFToString
is in charge of formatting text.
Synopsis
- data PyFCategory
- type family PyFClassify t :: PyFCategory
- class PyFToString t where
- pyfToString :: t -> String
- class PyfFormatFractional a where
- class PyfFormatIntegral i where
Default formatting classification
data PyFCategory Source #
The three categories of formatting in PyF
PyFIntegral | Format as an integral, no fractional part, precise value |
PyFFractional | Format as a fractional, approximate value with a fractional part |
PyFString | Format as a string |
type family PyFClassify t :: PyFCategory Source #
Classify a type to a PyFCategory
This classification will be used to decide which formatting to
use when no type specifier in provided.
Instances
String formatting
class PyFToString t where Source #
Convert a type to string This is used for the string formatting.
pyfToString :: t -> String Source #
Instances
PyFToString Char Source # | |
Show t => PyFToString t Source # | Default instance. Convert any type with a 'Show instance. |
Defined in PyF.Class pyfToString :: t -> String Source # | |
PyFToString String Source # | |
PyFToString ByteString Source # | |
Defined in PyF.Class pyfToString :: ByteString -> String Source # | |
PyFToString ByteString Source # | |
Defined in PyF.Class pyfToString :: ByteString -> String Source # | |
PyFToString Text Source # | |
PyFToString Text Source # | |
Real formatting (with optional fractional part)
class PyfFormatFractional a where Source #
Apply a fractional formatting to any type.
A default instance for any Real
is provided which internally converts to
Double
, which may not be efficient or results in rounding errors.
You can provide your own instance and internally use formatFractional
which does have the same signatures as pyfFormatFractional
but with a
RealFrac
constraint.
Instances
PyfFormatFractional Double Source # | This instance does not do any conversion. |
PyfFormatFractional Float Source # | This instance does not do any conversion. |
Real t => PyfFormatFractional t Source # | Default instance working for any |
Defined in PyF.Class pyfFormatFractional :: forall (t0 :: AltStatus) (t' :: UpperStatus) (k :: AlignForString). Format t0 t' 'Fractional -> SignMode -> Maybe (Int, AlignMode k, Char) -> Maybe (Int, Char) -> Maybe Int -> t -> String Source # |
Integral formatting
class PyfFormatIntegral i where Source #
Apply an integral formatting to any type.
A default instance for any Integral
is provided.
You can provide your own instance and internally use formatIntegral
which does have the same signatures as pyfFormatIntegral
but with an
Integral
constraint.
Instances
PyfFormatIntegral Char Source # | Returns the numerical value of a |
Integral t => PyfFormatIntegral t Source # | Default instance for any |