[Haskell-cafe] How to support multiple string types in Haskell?

KwangYul Seo kwangyul.seo at gmail.com
Thu Jul 14 00:40:13 UTC 2016


Hi all,

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?

Thanks,
Kwang Yul Seo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160714/52e56995/attachment.html>


More information about the Haskell-Cafe mailing list