[Haskell-cafe] Getting an attribute of an object

Dmitri Pissarenko mailing-lists at dapissarenko.com
Sat Feb 12 15:10:31 EST 2005


Sorry that I bother you again with my problem.

> It may be you'd profit from reading some of the Monad tutorials out there.

I followed your advice and read the "All about monads" tutorial. After I've
that I could fix one problem.

But now there is another one.

In the main program, there is following piece of code

let classifiedImagesWithData = ((return trainingSet) >>= readClassifiedImages)

let allImages = (getImages classifiedImagesWithData)

Signatures of readClassifiedImages and getImages are

readClassifiedImages :: [ClassifiedImage] -> [IO (ClassifiedImage, Image)]
getImages :: [(ClassifiedImage, Image)] -> [Image]

readClassifiedImages does some file I/O, so it is OK when its result is in the
IO monad.

getImages does not do any IO related stuff, so I declared it without the IO

The line

let allImages = (getImages classifiedImagesWithData)

of the above code snippet leads to following error:

     Couldn't match
         `(ClassifiedImage, Image)' against `IO (ClassifiedImage, Image)'
         Expected type: [(ClassifiedImage, Image)]
         Inferred type: [IO (ClassifiedImage, Image)]
     In the first argument of `getImages', namely
     In the definition of `allImages':
         allImages = (getImages classifiedImagesWithData)
Failed, modules loaded: TestLik, Lik, HUnit, HUnitText, HUnitBase, HUnitLang.

Is there a way to fix this problem apart from changing signature of getImage?

Thanks in advance

Dmitri Pissarenko
Dmitri Pissarenko
Software Engineer

More information about the Haskell-Cafe mailing list