Learn Haskell in 10 minutes
From HaskellWiki
Contents |
1 Overview
Haskell is a functional (that is, everything is done with function calls), statically, implicitly typed (types are checked by the compiler, but you don't have to declare them), lazy (nothing is done until it needs to be) language. It's closest popular relative is probably the ML family of languages.
The most common Haskell compiler is GHC. You can download GHC from http://www.haskell.org/ghc/download_ghc_661.html. GHC binaries are available for Linux, FreeBSD, MacOS, Windows, and Solaris. Once you've installed GHC, you get two programs you're interested in right now: ghc, and ghci. The first compiles Haskell libraries or applications to binary code. The second is an interpreter that lets you write Haskell code and get feedback right away.
2 Simple Expressions
You can type most math expressions directly into ghci and get an answer.
Prelude>15Prelude>
15Prelude>
16Strings are in "double quotes." You can concatenate them with
"Hello"Prelude>
"Hello, Haskell"
Calling functions is done by putting the arguments directly after the function. There are no parentheses as part of the function call:
Prelude>6Prelude>
6Prelude>
7Prelude>
1.4142135623730951Prelude>
TruePrelude>
7
3 The Console
I/O actions can be used to read from and write to the console. Some common ones include:
Prelude>Hello, HaskellPrelude>
9Prelude>
TrueThe
2 + 2 = 4Prelude>
ABCDE 12345Reading can be done with
4 16
(The 4 was input. The 16 was a result.)
There is actually another way to writemain = do putStrLn "What is 2 + 2?" x <- readLn if x == 4 then putStrLn "You're right!" else putStrLn "You're wrong!"
4 Simple Types
So far, not a single type has been mentioned
