From HaskellWiki
< Cookbook
Revision as of 09:00, 2 August 2009 by Lenny222 (talk | contribs) (Reading a string)

Jump to: navigation, search
Problem Solution Examples
reading a string getLine
Prelude> getLine
Foo bar baz          --> "Foo bar baz"

Printing a string

Strings can be output in a number of different ways.

Prelude> putStr "Foo"

As you can see, putStr does not include the newline character `\n'. We can either use putStr like this:

Prelude> putStr "Foo\n"

Or use putStrLn, which is already in the Standard Prelude

Prelude> putStrLn "Foo"

We can also use print to print a string, including the quotation marks.

Prelude> print "Foo"

Parsing command line arguments