[Haskell-cafe] "Parsing" a string

Mark Carroll markc at chiark.greenend.org.uk
Tue Jan 25 09:39:16 EST 2005


On Tue, 25 Jan 2005, Dmitri Pissarenko wrote:
(snip)
> I need to read the height and width, then "cut" them from the string, create
> an array (or finite map) of Int's (for this I need to know the height and
> width), and then recursively process the pixel values (i. e. put them into the
> array).

The simple way is probably to use functions like "lines" and "words" and
"map read". You can then use pattern-matching and recursive functions to
work your way through the file. For regular expressions you can use
Text.Regex in GHC.

However, for fancier parsing in GHC you can look at
Text.ParserCombinators.Parsec, and I recall that there was also talk on
this list of a nice regular expression library with syntax that goes
inline right into your Haskell code in a Perl-like way, but I also can't
immediately find any reference to that.

-- Mark



More information about the Haskell-Cafe mailing list