[Haskell-beginners] Haskell Output Help

Jan Jakubuv jakubuv at gmail.com
Fri Oct 23 11:42:48 EDT 2009


Hi,

seems to me like a job for `Text.PrettyPrint`:

    import Text.PrettyPrint
    
    ppString :: String -> Doc
    ppString = doubleQuotes . text

    ppList :: [Doc] -> Doc
    ppList = brackets . vcat . punctuate (text ",")

    pretty = ppList . map (ppList . map ppString)

The code is hopefully almost self-explaining (`vcat` does the line
breaking). The result looks as follows:

    *Main> pretty [["abc", "cde"], ["fgh", "ghi"]]
    [["abc",
      "cde"],
     ["fgh",
      "ghi"]]

Sincerely,
    jan.

On Thu, Oct 22, 2009 at 12:11:07PM -0700, Chandni Navani wrote:
> I have a list of lists which all contain strings.  [[String]].  I need to figure out how to print them so that after each individual string, there is a new line.
> 
> If this is the initial list [["abc", "cde"] ["fgh", "ghi"]]
> [["abc"
>   "cde"]
>  ["fgh",
>   "ghi"]]
> 
> Can anyone help me figure this out? Thanks.


-- 
Heriot-Watt University is a Scottish charity
registered under charity number SC000278.



More information about the Beginners mailing list