Please help me understand how to use the decode function from the HIP library.
class ImageFormat format => Readable img format where
decode :: format -> B.ByteString -> Either String img
I don't understand the first parameter, what should it be? Example would help.
Type classes are a little bit messy when you have fat arrows. The intention of typeclass
Readableis to defined the set of types which can be read from a givenImageFormat, where anImageFormatis a typeclass too. A little verbose but It'll be clear below; bear with me.Now, you can check in the documentation the instances of each type class. For example
ImageFormathas these instances.So, your first argument should be one of those. But not only so, you also need to be sure that the pair
img formatimplements theReadabletypeclass. For exampleReadablehas these instances (among others):Readable (Image VS RGB Double) PNGReadable [Image VS RGB Double] (Seq GIF)You can interpret these as "from a
PNGI can read andImage VS RGB Doubleand from a sequence ofGIFI can read[Image VS RGB Double](list of images)". But more important there is no(!!) instanceReadable [Image VS RGB Double] PNGWhich means that you can't read a list of images from a PNG.
That being said, how do you use the
decodefunction?. well, we know that the first argument should be one of the instances ofImageFormat, so lets pickPNG