[Haskell-cafe] IO Help

Mark Wallsgrove mark at simplycompute.co.uk
Thu May 8 08:59:06 EDT 2008


Thank you very much for your fast response!

Ok, that is now changed, but everything else in my program is expecting 
Catalogue without IO. Is there a way to change IO Catalogue into Catalogue?

Henning Thielemann wrote:
> 
> On Thu, 8 May 2008, Mark Wallsgrove wrote:
> 
>> Problem now is reading the data back into the program. When I read the 
>> data
>> back into the program it comes as IO [Track]. This is the code I have 
>> been
>> using to load the data:
>>
>>
>> loadData :: String -> Catalogue
>> loadData fileName = do x <- readFile fileName
>>                       return (read x :: Catalogue)
> 
> type should be
> 
>   loadData :: String -> IO Catalogue
> 
> 
> But using plainly 'read' may not satisfy you, because the program will 
> abort unrecoverably if the file has corrupt content. You may want to use 
> 'reads' and check manually if parsing was successful:
> 
> case reads x of
>    [(cat, "")] -> return cat
>    _ -> fail "corrupt file content"
> 



More information about the Haskell-Cafe mailing list