extracting a vector from a Repa Array

64 views Asked by At

hello everyone I have this function in haskell that let me extract a Repa array from bitmap grayScale

readImageFromBMPa
        :: FilePath
        -> IO (Either Error (Array U DIM2 ( Word8)))

{-# NOINLINE readImageFromBMPa #-}
readImageFromBMPa filePath
 = do   ebmp    <- readBMP filePath

        case ebmp of
         Left err       -> return $ Left err
         Right bmp      
          -> do arr    <- readImageFromBMPPrime  bmp
                return  $ Right arr

I searched on way to extract a vector from this function output I I found toUnboxed Function like this

let a =  Prelude.map (\(v) -> toUnboxed (readImageFromBMPa v))(fst ns)

I get the following error • Couldn't match expected type ‘Array U sh0 e’ with actual type ‘IO (Either Error (Array U DIM2)

is there a way I can do the conversion thanks

1

There are 1 answers

0
Akihito KIRISAKI On

As the error says, type passed to toUnboxed is wrong. Type Array U DIM2 you want is wrapped by IO a monad and Either a b monad. It needs to peel off them in order to deal with the content. This sample is same problem.

main = do
    str <- getLine  :: IO String
    putStrLn str -- putStrLn :: String -> IO ()