[Haskell-cafe] (no subject)
Sebastian Sylvan
sebastian.sylvan at gmail.com
Fri Aug 21 21:03:10 EDT 2009
On Fri, Aug 21, 2009 at 11:42 PM, Stavenga, G.C. <G.C.Stavenga at uu.nl> wrote:
>
>
> 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?
>
I usually just whip up a quick parser using
Text.ParserCombinators.Parsec<http://www.haskell.org/ghc/docs/latest/html/libraries/parsec/Text-ParserCombinators-Parsec.html>
--
Sebastian Sylvan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090821/52aaf7ca/attachment.html
More information about the Haskell-Cafe
mailing list