[Haskell-cafe] Re: Embedding newlines into a string?

Luke Palmer lrpalmer at gmail.com
Tue Apr 15 00:45:19 EDT 2008


On Tue, Apr 15, 2008 at 3:45 AM, Benjamin L. Russell
<dekudekuplex at yahoo.com> wrote:
> hanoi_shower ((a, b) : moves)
>     | null moves = "Move " ++ show a ++ " to "++ show
>  b ++ "."
>     | otherwise == "Move " ++ show a ++ " to "++ show
>  b ++ "." ++ hanoi_shower moves

More idiomatic pedantry:  the way you will see most Haskellers write
this style of function is by pattern matching rather than guards:

hanoi_shower [] = ""
hanoi_shower ((a,b):moves) = "Move " ++ show a ++ " to " ++ show b ++
".\n" ++ hanoi_shower moves

Luke


More information about the Haskell-Cafe mailing list