[Haskell-cafe] IO Help
Henning Thielemann
lemming at henning-thielemann.de
Thu May 8 08:55:19 EDT 2008
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