[Haskell] Re: IO functions reference?

Ketil Malde ketil+haskell at ii.uib.no
Tue Sep 27 08:55:28 EDT 2005

Creighton Hogg <wchogg at lotus.hep.wisc.edu> writes:

> So I looked to see if there were any standard functions for 
> taking an input line and turning it into a list, and I 
> couldn't find any.  How would one do this in Haskell?  I 
> just want to parse the line into a list of strings, and 
> from there recover the numbers from the strings.

In other words, you want to split "lines" into "words" and "read"
numbers from the result?  Perhaps you should check the Prelude again.

> That doesn't seem easy though, unelss there's something I'm 
> missing.

Reading from and writing to the outside world must take place in the
IO monad.  The parsing and other manipulation can be done by
functions, use e.g. "let" in the IO code to construct intermediate

E.g., main can look like:

main = do
     f <- readFile "table.txt"
     let x = my_parse_function f
     putStrLn x

my_parse_function :: String -> String

If I haven't seen further, it is by standing in the footprints of giants

More information about the Haskell mailing list