[Haskell-cafe] How to support multiple string types in Haskell?
kwangyul.seo at gmail.com
Thu Jul 14 00:40:13 UTC 2016
There are multiple string types in Haskell – String, lazy/strict
ByteString, lazy/strict Text to name a few. So to make a string handling
function maximally reusable, it needs to support multiple string types.
One approach used by TagSoup library is to make a type class StringLike
which represents the polymorphic string type and uses it where a String
type is normally needed. For example,
parseTags :: StringLike str => str -> [Tag str]
Here parseTags takes a StringLike type instead of a fixed string type.
Users of TagSoup can pick any of String, lazy/strict ByteString,
lazy/strict Text because they are all instances of StringLike type class.
It seems StringLike type class is quite generic but it is used only in the
TagSoup package. This makes me wonder what is the idiomatic way to support
multiple string types in Haskell. What other approaches do we have?
Kwang Yul Seo
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe