Everyone knows Show
. But what about:
class ShowText a where showText :: a -> Text
I can't find this anywhere. Why?
The shows functions return a function that prepends the output String to an existing String . This allows constant-time concatenation of results using function composition.
An instance of a class is an individual object which belongs to that class. In Haskell, the class system is (roughly speaking) a way to group similar types. (This is the reason we call them "type classes"). An instance of a class is an individual type which belongs to that class.
The problem with creating the Text directly is you still need to know the overall size of the strict Text block before filling it in. You can do better with a Builder scheme and using Data.Text.Lazy. Dan Doel does this in bytestring-show, but I'm not aware of an equivalent for Text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With