Embedding newlines into a string? [Was: Re: [Haskell-cafe]
Separate a string into a list of strings]
Neil Mitchell
ndmitchell at gmail.com
Mon Apr 14 03:30:33 EDT 2008
Hi
On Mon, Apr 14, 2008 at 8:22 AM, Benjamin L. Russell
<dekudekuplex at yahoo.com> wrote:
> A friend and I were working on a Haskell version of
> Towers of Hanoi yesterday, and I tried writing out the
> program today, but got stuck on outputting newlines as
> part of the string; viz:
> | n == 1 = putStrLn ("Move " ++ show source ++ " to
> " ++ show dest ++ "." ++ show '\n')
show '\n' = "\\n"
"\n" == "\n"
Therefore:
> | n == 1 = putStrLn ("Move " ++ show source ++ " to
> " ++ show dest ++ "." ++ "\n")
Note that you need the brackets, an in general don't call show on a
String or a Char.
Thanks
Neil
More information about the Haskell-Cafe
mailing list