[Haskell-cafe] (no subject)

Stavenga, G.C. G.C.Stavenga at uu.nl
Fri Aug 21 18:42:27 EDT 2009

Hi, I'm just started to learn Haskell. Coming from a programming contest
background (where it is important to be able to solve problems in a small
amount of code) I'm wondering what the best way is for simple IO.

A typical input file (in a programming contest) is just a bunch of numbers
which you want to read one by one (sometimes interspersed with strings). In
C/C++ this is easily done with either scanf or cin which reads data
separated by spaces. In Haskell I have not found an equally satisfactionary
method. The methods I know of

1) Stay in the IO monad and write your own readInt readString functions. A lot
of code for something easy.

2) Use interact together with words and put the list of lexemes in a State
monad and define getInt where at least you can use read.

3) Use ByteString.Char8 which has readInt (but I couldn't find a
readString). But one has to put it also in a State monad.

I think that there must be standard function that can do this. What do
experienced Haskellers use?

Thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090821/c797ed79/attachment.html

More information about the Haskell-Cafe mailing list