Difference between revisions of "User:Lenny222/Haskell explained to the busy"
Line 79: | Line 79: | ||
=== . === |
=== . === |
||
The dot "." is used to compose functions in point-free style, similar to "$". |
The dot "." is used to compose functions in point-free style, similar to "$". |
||
+ | |||
− | For example: |
||
+ | Example: |
||
<haskell>foo x = h $ g $ f x</haskell> |
<haskell>foo x = h $ g $ f x</haskell> |
||
is the same as |
is the same as |
||
Line 86: | Line 87: | ||
=== ` === |
=== ` === |
||
A function enclosed in back ticks "`"s can be used as an infix operator. |
A function enclosed in back ticks "`"s can be used as an infix operator. |
||
+ | |||
− | For example: |
||
+ | Example: |
||
<haskell>subtract 2 10</haskell> |
<haskell>subtract 2 10</haskell> |
||
is the same as |
is the same as |
||
Line 96: | Line 98: | ||
=== : === |
=== : === |
||
The colon ":" is an infix operator that adds an element to the beginning of a list |
The colon ":" is an infix operator that adds an element to the beginning of a list |
||
+ | |||
− | For example: |
||
+ | Example: |
||
<haskell>1 : [2,3]</haskell> |
<haskell>1 : [2,3]</haskell> |
||
will result in the new list |
will result in the new list |
||
Line 113: | Line 116: | ||
=== $ === |
=== $ === |
||
The dollar sign "$" is a way to compose functions, but avoid typing too many brackets. |
The dollar sign "$" is a way to compose functions, but avoid typing too many brackets. |
||
+ | |||
− | For example: |
||
+ | Example: |
||
<haskell>foo x = h (g (f x))</haskell> |
<haskell>foo x = h (g (f x))</haskell> |
||
is the same as |
is the same as |
||
Line 120: | Line 124: | ||
=== -- === |
=== -- === |
||
The double dash "-- " (a trailing space is necessary) begins a '''single-line comment'''. The rest of the line will be ignored by the compiler. |
The double dash "-- " (a trailing space is necessary) begins a '''single-line comment'''. The rest of the line will be ignored by the compiler. |
||
+ | |||
− | For example: |
||
+ | Example: |
||
<haskell>-- Sort the list |
<haskell>-- Sort the list |
||
sort [3,2,4] |
sort [3,2,4] |
||
Line 132: | Line 137: | ||
=== {- -} === |
=== {- -} === |
||
"{- " (a trailing space is necessary) and "-}" define a '''block comment'''. Everything in between will be ignored by the compiler. |
"{- " (a trailing space is necessary) and "-}" define a '''block comment'''. Everything in between will be ignored by the compiler. |
||
+ | |||
− | For example: |
||
+ | Example: |
||
<haskell> |
<haskell> |
||
{- |
{- |
||
Line 145: | Line 151: | ||
=== data === |
=== data === |
||
"data" defines a new data type. TODO |
"data" defines a new data type. TODO |
||
+ | |||
− | For example: |
||
+ | Example: |
||
<haskell>data colors = Red | Blue | Green</haskell> |
<haskell>data colors = Red | Blue | Green</haskell> |
||
Revision as of 10:41, 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 a lazy programming language?
What is good about that?
What is a statically typed programming language
What is good about that?
Is Haskell Open Source?
Why the name "Haskell"?
Haskell is named after the American mathematician Haskell Curry
Basics
Question | Answer |
---|---|
What is an infix operator? | Infix operators are normal functions. TODO: symbols, round brackets
For example: 5 + 2
is the same as (+) 5 2
|
Are there any prefix operators? | TODO |
How do you define a function in Haskell? | TODO
For example: add x y = x + y
|
Didn't you say Haskell is statically typed? | It is. TODO |
What is point-free style? | Point-free style is a way to define functions solely as a composition of other functions, leaving out arguments in the definition.
For example: takeFive x = take 5 x
is the same as takeFive = take 5
in point-free style. |
What is currying? | TODO |
What is pattern matching? | TODO |
Advanced
Question | Answer |
---|---|
What is a Monad? | TODO |
What is the meaning of "forall"? | TODO |
Special characters, expressions and keywords
.
The dot "." is used to compose functions in point-free style, similar to "$".
Example:
foo x = h $ g $ f x
is the same as
foo = h . g . f
`
A function enclosed in back ticks "`"s can be used as an infix operator.
Example:
subtract 2 10
is the same as
2 `subtract` 10
'
Backtick TODO: single characters, common usage in function names
:
The colon ":" is an infix operator that adds an element to the beginning of a list
Example:
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
$
The dollar sign "$" is a way to compose functions, but avoid typing too many brackets.
Example:
foo x = h (g (f x))
is the same as
foo x = h $ g $ f x
--
The double dash "-- " (a trailing space is necessary) begins a single-line comment. The rest of the line will be ignored by the compiler.
Example:
-- Sort the list
sort [3,2,4]
or
sort [3,2,4] -- Sort the list
[ ]
The square brackets TODO
{- -}
"{- " (a trailing space is necessary) and "-}" define a block comment. Everything in between will be ignored by the compiler.
Example:
{-
The next line would sort the list, if it wasn't in a block comment
sort [3,2,4]
-}
{-# #-}
"{-# " (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
newtype
TODO
type
TODO