Skip to content

getOptions'.parseLanguage(2) went past eof token

{-# LANGUAGE -XFlexibleContexts #-}
module Pngloadtest where
import Control.Monad
import Control.Arrow
import Codec.Image.PNG
import Data.Array.MArray
import Data.Array.Storable
import GHC.Word
--import Data.Array.MArray
import qualified Data.Matrix.DenseMatrix as DM

openImage :: IO PNGImage
openImage = do
  a <- loadPNGFile "C:/users/saftarn/desktop/datasets/pics/face2.png"
  case a of Left err  -> error err
            Right img -> return img

dims :: PNGImage -> (Int, Int)
dims img = join (***) fromIntegral $ dimensions img 

size :: PNGImage -> Int
size img = uncurry (*) $ dims img 


--imgToList :: (MArray StorableArray Word8 m, Num b) => PNGImage -> m [b]
imgToList img = do
  es <- getElems $ imageData img
  return $ map fromIntegral es

imgToMatrix :: (MArray StorableArray Word8 m) => PNGImage -> 
               m DM.DenseMatrix
imgToMatrix im = do
  let (w,_) = dims im
  xs <- imgToList im
  return $ DM.fromFlatList w xs

main = do
  im <- openImage
  a <- imgToList im
  print $ dims im
  print $ size im
  --print a





*Pngloadtest> :load "ComputerVision/Pngloadtest.hs"
[1 of 2] Compiling Data.Matrix.DenseMatrix ( Data\Matrix\DenseMatrix.hs, interpreted )
[2 of 2] Compiling Pngloadtest      ( ComputerVision\Pngloadtest.hs, interpreted )

ComputerVision\Pngloadtest.hs:29:0:
    Non type-variable argument
      in the constraint: MArray StorableArray Word8 m
    (Use -XFlexibleContexts to permit this)
    In the type signature for `imgToMatrix':
      imgToMatrix :: (MArray StorableArray Word8 m) =>
                     PNGImage -> m DM.DenseMatrix
Failed, modules loaded: Data.Matrix.DenseMatrix.
*Data.Matrix.DenseMatrix> :load "ComputerVision/Pngloadtest.hs"
: panic! (the 'impossible' happened)
  (GHC version 6.10.2 for i386-unknown-mingw32):
	getOptions'.parseLanguage(2) went past eof token

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

> 

Works if using: {-# LANGUAGE FlexibleContexts #-}

Edited by Simon Marlow
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information