Learn Haskell in 10 minutes
Revision as of 05:50, 13 July 2007
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>
16Strings are in "double quotes." You can concatenate them with
Calling functions is done by putting the arguments directly after the function. There are no parentheses as part of the function call:Prelude>
3 The Console
I/O actions can be used to read from and write to the console. Some common ones include:Prelude>
2 + 2 = 4Prelude>
ABCDE 12345Reading can be done with
(The 4 was input. The 16 was a result.)There is actually another way to write
main = 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