Personal tools


From HaskellWiki

< Cookbook(Difference between revisions)
Jump to: navigation, search
(smaller headlines)

Revision as of 11:32, 9 July 2009

1 Reading a string

Strings can be read as input using getLine.

Prelude> getLine
Foo bar baz
"Foo bar baz"

2 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"

3 Parsing command line arguments