Difference between revisions of "User:Lenny222/Haskell explained to the busy"
Line 22: | Line 22: | ||
== Functions == |
== Functions == |
||
+ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
+ | |||
+ | === How do you define a function? === |
||
+ | TODO |
||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |TODO |
||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
=== What is an infix operator? === |
=== What is an infix operator? === |
||
Line 42: | Line 63: | ||
TODO: (-) |
TODO: (-) |
||
− | |||
⚫ | |||
− | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | |||
⚫ | |||
⚫ | |||
=== What is point-free style? === |
=== What is point-free style? === |
||
Line 73: | Line 80: | ||
=== What is currying? === |
=== What is currying? === |
||
+ | TODO |
||
=== What is pattern matching? === |
=== What is pattern matching? === |
||
+ | TODO |
||
+ | |||
+ | == Data types == |
||
+ | |||
+ | === Lists === |
||
+ | TODO |
||
+ | |||
+ | === Strings === |
||
+ | TODO |
||
+ | |||
+ | === Tupels === |
||
+ | TODO |
||
+ | |||
+ | === Tuples === |
||
+ | === User-defined types === |
||
== Comments == |
== Comments == |
||
Line 113: | Line 136: | ||
|} |
|} |
||
− | == Advanced == |
||
− | |||
⚫ | |||
⚫ | |||
== Special characters, expressions and keywords == |
== Special characters, expressions and keywords == |
Revision as of 12:03, 1 October 2009
You have heard about Haskell but don't have the time to find out what it is?
This page may be for you.
Introduction
What is Haskell?
Haskell is a purely functional, lazy, statically typed programming language
What is a purely functional programming language?
What is good about that?
What is lazy evaluation?
What is good about that?
What is static typing?
What is good about that?
Is Haskell Open Source?
Why the name "Haskell"?
Haskell is named after the American mathematician Haskell Curry
Functions
How do you use a function?
TODO
What is the "Prelude"?
TODO
How do you define a function?
TODO
Answer | Example |
---|---|
TODO | add x y = x + y
|
Didn't you say Haskell is statically typed? It is. TODO
What is an infix operator?
Answer | Example |
---|---|
Infix operators are normal functions.
TODO: symbols, round brackets |
5 + 2
is the same as (+) 5 2
|
Are there any prefix operators?
TODO: (-)
What is point-free style?
Answer | Example |
---|---|
Point-free style is a way to define functions solely as a composition of other functions.
Function arguments do not show up in the function definition. |
The point-free style version of
takeFive x = take 5 x
is takeFive = take 5
|
What is currying?
TODO
What is pattern matching?
TODO
Data types
Lists
TODO
Strings
TODO
Tupels
TODO
Tuples
User-defined types
Comments
How do you write single-line comments?
Answer | Example |
---|---|
Everything between a double dash "--" followed by a space and the end of the line is a single-line comment.
A single-line comment will be ignored by the compiler. |
-- Sort the list
sort [3,2,4]
or sort [3,2,4] -- Sort the list
|
How do you write a block comment?
Answer | Examples |
---|---|
Everything between "{-" followed by a space and "-}" is a block comment.
A block comment will be ignored by the compiler. |
{-
The next line would sort the list, if it wasn't in a block comment
sort [3,2,4]
-}
or sort [3,2,4] {- Block quotes can also be used for single line comments -}
|
Special characters, expressions and keywords
.
Meaning | Example |
---|---|
The dot "." is used to compose functions in point-free style, similar to "$". | foo = h . g . f
is the same as foo x = h $ g $ f x
is the same as foo x = h (g (f x))
|
`
Meaning | Example |
---|---|
A function enclosed in back ticks "`" can be used as an infix operator. | subtract 2 10
which is the same as 2 `subtract` 10
|
'
Tick TODO: single characters, common usage in function names
:
Meaning | Example |
---|---|
The colon ":" is an infix operator that adds an element to the beginning of a list. | 1 : [2,3]
will result in the new list [1,2,3]
|
::
The double colon TODO
|
Downslash TODO: pattern matching, data types
\
Backslash TODO: multiline strings, lambda function
$
Meaning | Example |
---|---|
The dollar sign "$" is a way to compose functions, without typing too many brackets. | foo x = h $ g $ f x
is the same as foo x = h (g (f x))
|
--
Meaning | Example |
---|---|
The double dash "--" followed by a space begins a single-line comment. | -- A single-line comment
|
[ ]
The square brackets TODO
{- -}
Meaning | Examples |
---|---|
Everything between "{-" followed by a space and "-}" is a block comment. | {-
This is a block comment
-}
|
{-# #-}
"{-# " (the trailing space is necessay) and "#-}" define compiler pragmas. TODO
data
"data" defines a new data type. TODO
Example:
data colors = Red | Blue | Green
deriving
TODO
forall
TODO
newtype
TODO
type
TODO