Typeclass for functions taking different kinds of strings

Hello It seems like a very common issue to have an API like: foo :: String -> Foo fooBS :: ByteString -> Foo fooLBS:: L.ByteString -> Foo is there currently a library that makes unifying them easy? Below is attached one try at this, does it make sense? I'm thinking of uploading it to Hackage but would like comments first. With the library the above code is transformed into: foo :: StringLike string => string -> Foo - Taru Karttunen

On Wed, Aug 5, 2009 at 1:24 PM, Taru Karttunen
Hello
It seems like a very common issue to have an API like:
foo :: String -> Foo fooBS :: ByteString -> Foo fooLBS:: L.ByteString -> Foo
is there currently a library that makes unifying them easy?
They cannot be completely unified. A sequence of Unicode characters (String) is not the same kind of thing as a sequence of bytes (ByteString). Going between the two requires an encoding. A shared abstraction would support a subset of operations that make sense on all sequences. Cheers, Johan

Hi
is there currently a library that makes unifying them easy?
I currently use this library: http://community.haskell.org/~ndm/darcs/tagsoup/Text/StringLike.hs Not yet released, and rather specific to what I was wanting to do, but does work for me. I'm happy for people to steal bits from that as they want. Thanks Neil

Excerpts from Neil Mitchell's message of Wed Aug 05 16:36:06 +0300 2009:
I currently use this library:
http://community.haskell.org/~ndm/darcs/tagsoup/Text/StringLike.hs
It looks nice but is not really a solution for passing large amounts of data efficiently. Converting everything to String creates too much overhead for large chunks of data. - Taru Karttunen

Hi
It looks nice but is not really a solution for passing large amounts of data efficiently. Converting everything to String creates too much overhead for large chunks of data.
There is uncons, which never creates big strings. But yes, adding more bulk operations (i.e. lookup) might be necessary to make it widely useful. Thanks Neil
participants (3)
-
Johan Tibell
-
Neil Mitchell
-
Taru Karttunen