[Haskell-cafe] The Proliferation of List-Like Types

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Wed Feb 20 18:13:34 EST 2008

On Wed, 2008-02-20 at 08:39 -0600, John Goerzen wrote:

> * The iconv library works only on lazy ByteStrings, and does not
>    handle Strings or strict ByteStrings

There is a very good reason for this. The right solution in this
particular example is not to overload every internal string operation in
the iconv lib (which would be far far too slow) but to convert to/from
your favourite representation on the edge. So in this case those
conversions would be pack/unpack or the similar equivalents for strict
<-> lazy bytestrings.

If we want it to be generic then we want a class of string like things
that provides conversions only, not operations.

For example we could export iconv as:

iconv :: StringLike string => Encoding -> Encoding -> string -> string
iconv to from = (convertStringRep :: Lazy.ByteString -> string)
              . theRealIconv
              . (convertStringRep :: string -> Lazy.ByteString)

class StringLike string where

convertStringRep :: (StringLike s1, StringLike s2) => s1 -> s2
-- analogous to fromIntegral


More information about the Haskell-Cafe mailing list