| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Display
Description
Display human-readable values to the user efficiently. See the
display method for documentation.
Use the OverloadedStrings language extension when using this module
to produce Builder values conveniently e.g. "Hello" <> display name.
- display :: Display a => a -> Builder
- displayByteString :: Display a => a -> ByteString
- displayLazyByteString :: Display a => a -> ByteString
- displayString :: Display a => a -> String
- displayText :: Display a => a -> Text
- displayLazyText :: Display a => a -> Text
- class Display a where
Printing method
display :: Display a => a -> Builder Source #
Display a value in a human-readable format. This is the
opposite of the Show class which is intended for programmers to
read. See Display for how to use this for your own types.
- Writing to file or output: The
Buildercan be written directly to a handle withhPutBuildervery efficiently as UTF-8. This is the preferred method when writing to stdout or a file. - Writing to a string: Use one of the functions in Conversions
like
displayByteStringordisplayString(when needed).
Use the functions in Data.ByteString.Builder for hex encodings of numbers and strings.
To append Builder you can use the Monoid instance, for
example to print things comma-separated, you can use
intersperse and mconcat:
mconcat (intersperse ", " (map display [1, 4, 5]))
This example requires the OverloadedStrings language extension.
Conversions
displayByteString :: Display a => a -> ByteString Source #
Display to a ByteString value.
displayLazyByteString :: Display a => a -> ByteString Source #
Display to a ByteString value.
displayString :: Display a => a -> String Source #
Display to a String value. Very inefficient. Only use when you
are forced to by another API.
displayText :: Display a => a -> Text Source #
Display to a Text value. Inefficient. Only use when you have to.
displayLazyText :: Display a => a -> Text Source #
Display to a Text value. Inefficient. Only use when you have to.
The class
class Display a where Source #
Display a value in a human-readable format. This is the opposite
of the Show class which is intended for programmers to read, and
can be used alongside Show.
For example, consider: Maybe String
>>>show (Just "abc")Just "abc">>>show NothingNothing
whereas display is meant for printing to users, so you might
write this:
>>>display (Just "abc")abc>>>display Nothing""
You can safely use newtype deriving with this type, e.g.
newtype Name = Name Text deriving (Show, Display)
Instances for exceptions can be written like this:
data MyException = SomeProblem deriving (Show, Typeable) instance Exception MyException where displayException = displayString
Minimal complete definition
Methods
display :: a -> Builder Source #
Display a value in a human-readable format. This is the
opposite of the Show class which is intended for programmers to
read. See Display for how to use this for your own types.
- Writing to file or output: The
Buildercan be written directly to a handle withhPutBuildervery efficiently as UTF-8. This is the preferred method when writing to stdout or a file. - Writing to a string: Use one of the functions in Conversions
like
displayByteStringordisplayString(when needed).
Use the functions in Data.ByteString.Builder for hex encodings of numbers and strings.
To append Builder you can use the Monoid instance, for
example to print things comma-separated, you can use
intersperse and mconcat:
mconcat (intersperse ", " (map display [1, 4, 5]))
This example requires the OverloadedStrings language extension.
Instances
| Display Char Source # | |
| Display Double Source # | |
| Display Float Source # | |
| Display Int Source # | |
| Display Int8 Source # | |
| Display Int16 Source # | |
| Display Int32 Source # | |
| Display Int64 Source # | |
| Display Integer Source # | |
| Display Word Source # | |
| Display Word8 Source # | |
| Display Word16 Source # | |
| Display Word32 Source # | |
| Display Word64 Source # | |
| Display ByteString Source # | |
| Display ByteString Source # | |
| Display Builder Source # | |
| Display Text Source # | |
| Display Text Source # | |
| Display [Char] Source # | |
| Display a => Display (Maybe a) Source # | |
| (Display a, Display b) => Display (Either a b) Source # | |