Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent of the Show typeclass for Data.Text?

Everyone knows Show. But what about:

class ShowText a where   showText :: a -> Text 

I can't find this anywhere. Why?

like image 787
jameshfisher Avatar asked Jun 11 '12 22:06

jameshfisher


People also ask

What is show in Haskell?

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.

What is instance Haskell?

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.


1 Answers

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.

like image 115
Edward Kmett Avatar answered Nov 09 '22 05:11

Edward Kmett