Search code examples
haskellbytestring

Folding over [Word8] and ByteString with same function?


It turns out that there is no instance of Foldable available for ByteString. I'd like to write a function that uses foldl' on either [Word8] or ByteString but I can't. Since a ByteString is, data-wise, the same as [Word8], it seems that I should be able to.

Is there a package available that integrates the two or must I roll my own with a type class?


Solution

  • Have a look at the MonoFoldable class defined in mono-traversable package.

    It has instances for both ByteString and [a].