PDA

View Full Version : IO [a] to [a] conversion? (Haskell)


CheeseMonger
02-21-2004, 02:25 PM
After reading in a string from a file, my function returns a IO [Char] type.

How can I use this data with functions that require a [Char] or [a]type?

For example, the display function returns a string read from the file:

MatIO> display
"SQ345 ","10","10","08","05","Manchester","Singapore"

But if I try to reverse it:

MatIO> reverse display
ERROR - Type error in application
*** Expression : reverse display
*** Term : display
*** Type : IO [Char]
*** Does not match : [a]

How can I get around this issue?

Cheers for any help.

jemfinch
02-21-2004, 05:33 PM
You need to use such functions while you're still in the IO monad. I'm sure someone else who knows Haskell better than I do can show you the exact syntax.

Jeremy

CheeseMonger
02-22-2004, 12:20 PM
Cheers for the reply.

For other people that come across this 'feature', I finally found a link that explains it in greater depth:

http://www.haskell.org/hawiki/ThatAnnoyingIoType