Difference between revisions of "Cookbook/Interactivity"
< Cookbook
Jump to navigation
Jump to search
(smaller headlines) |
|||
Line 1: | Line 1: | ||
− | = Reading a string = |
+ | == Reading a string == |
Strings can be read as input using [http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v%3AgetLine getLine]. |
Strings can be read as input using [http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v%3AgetLine getLine]. |
||
<haskell> |
<haskell> |
||
Line 7: | Line 7: | ||
</haskell> |
</haskell> |
||
− | = Printing a string = |
+ | == Printing a string == |
Strings can be output in a number of different ways. |
Strings can be output in a number of different ways. |
||
<haskell> |
<haskell> |
||
Line 29: | Line 29: | ||
</haskell> |
</haskell> |
||
− | = Parsing command line arguments = |
+ | == Parsing command line arguments == |
TODO |
TODO |
Revision as of 11:32, 9 July 2009
Reading a string
Strings can be read as input using 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"
FooPrelude>
As you can see, putStr does not include the newline character `\n'. We can either use putStr like this:
Prelude> putStr "Foo\n"
Foo
Or use putStrLn, which is already in the Standard Prelude
Prelude> putStrLn "Foo"
Foo
We can also use print to print a string, including the quotation marks.
Prelude> print "Foo"
"Foo"
Parsing command line arguments
TODO