[Haskell-cafe] Getting an attribute of an object

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


Hello!

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
done
that I could fix one problem.

But now there is another one.

In the main program, there is following piece of code

<code-snippet>
let classifiedImagesWithData = ((return trainingSet) >>= readClassifiedImages)

let allImages = (getImages classifiedImagesWithData)
</code-snippet>

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
monad.

The line

let allImages = (getImages classifiedImagesWithData)

of the above code snippet leads to following error:

<error>
ExperimentalYaleFaceDb.hs:43:
     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
         `classifiedImagesWithData'
     In the definition of `allImages':
         allImages = (getImages classifiedImagesWithData)
Failed, modules loaded: TestLik, Lik, HUnit, HUnitText, HUnitBase, HUnitLang.
</error>

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

Thanks in advance

Dmitri Pissarenko
--
Dmitri Pissarenko
Software Engineer
http://dapissarenko.com



More information about the Haskell-Cafe mailing list