[Haskell-cafe] Parse text difficulty

Ketil Malde ketil+haskell at ii.uib.no
Thu Dec 9 05:03:38 EST 2004

Douglas Bromley <doug.bromley at gmail.com> writes:

> I've show(n) a particular data type and it shows up as:
> [([2,6],"British"),([1],"Charles"),([1,8],"Clarke"),([2,6],"Council"),([2],"Edinburgh"),([1],"Education"),([4],"Increasingly")]

Let me guess: type [([Integer],String)]?

> What I want to do is format that nicely into a table.

Since you (probably) want one list entry on a line, why not
format each entry as a string, and output each string as a line?  You
may find the function "unlines" to be helpful.

> The best way of doing (I thought) was to:
> Remove the first "[(" and final ")]"
> Then replace "),(" with a newline(\n)

If you really want to do this (reformat the string), you could perhaps
write a function that substitutes a substring for something else,
perhaps using "isPrefixOf", "drop" and "take".  But this will be a
more fragile design than working from the original data strucure.

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

More information about the Haskell-Cafe mailing list