How to use Either String (IO())

172 Views Asked by At

I'm working with Juicy Pixels library in Haskell and i want to make a GIF animation with a list of image PixelRGB8. There's a function that do that (writeGifAnimation), but it returns a type that i don't know how to use (Either String (IO())). Can anybody help me?

The way i'm using it: writeGifAnimation "test.gif" 1 LoopingForever image_list

The error: Couldn't match expected type ‘IO ()’ with actual type ‘Either String (IO ())’

The library documentation: https://hackage.haskell.org/package/JuicyPixels-3.3.7/docs/Codec-Picture.html#v:savePngImage:~:text=the%20same%20delay.-,writeGifAnimation,-%3A%3A%20FilePath%20%2D%3E

1

There are 1 best solutions below

0
On

You should check whether it is a Left s with s an error, or a Right i with i an IO () action, so:

main :: IO ()
main = do
    -- …
    case writeGifAnimation "test.gif" 1 LoopingForever image_list of
        Left s -> fail s
        Right i -> i
    -- …