[Haskell-cafe] How to convert from "IO String" to String

Alistair Bayley alistair at abayley.org
Tue Jan 25 16:13:03 EST 2005


Try

 > l = [ 0, 255, 255, 255, 255, 0, 255, 255, 255, 255
 >     , 0, 255, 255, 255, 255, 0]
 > testConvertToList01 = TestCase $ do
 >   img <- readImage "../data-test/diagonalImage.pgm"
 >   assertEqual "" l (convertToList img)

A TestCase is just an IO action (take a look at the HUnit source code).


Alistair.


Dmitri Pissarenko wrote:
> Hello!
> 
> Thanks for your answer!
> 
>> You probably want something like...
>>
>> l = [0, 255, 255, 255, 255, 0, 255, 255, 255, 255, 0, 255, 255, 255, 
>> 255, 0]
>> testConvertToList01 = do img <- readImage 
>> "../data-test/diagonalImage.pgm"
>>                          return $ TestCase $ assertEqual "" l 
>> (convertToList img)
> 
> 
> When I use this test case definition, I'm getting an error when 
> constructing
> the test suite:
> 
> tests = TestList [testCommentLine01, testCommentLine02, 
> testConvertToList01]
> 
> GHCi writes
> 
> TestLik.hs:22:
>     Couldn't match `Test' against `IO Test'
>         Expected type: Test
>         Inferred type: IO Test
>     In the list element: testConvertToList01
>     In the first argument of `TestList', namely
>         `[testCommentLine01, testCommentLine02, testConvertToList01]'
> 
> Best regards
> 
> Dmitri Pissarenko
> -- 
> Dmitri Pissarenko
> Software Engineer
> http://dapissarenko.com
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 


More information about the Haskell-Cafe mailing list