Reputation: 74364
I'd like to offer a "user friendly" generic interface for a library I'm writing. It seems like the thing that ought to already exist, so I'd like to not reinvent the wheel.
At it's heart, the library is a wrapper over a lot of C functions that take unsigned char[]
. Right now I'm using vector
since it was easy to understand how to use Mutable
to allocate and freeze
C arrays being written by the library, but the more popular interface would be ByteString
. Is there a good way to transparently convert them? And/or a good way to offer a generic interface for both of them?
As an example, I'd like to be able to write a function
doIt :: ByteArrayLike ba => ba -> ba
and have it operate on ByteString
and Vector Word8
identically.
Upvotes: 3
Views: 150