Difference between revisions of "User:Lenny222/Haskell explained to the busy"

From HaskellWiki
Jump to navigation Jump to search
 
Line 1: Line 1:
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 [[#What is a purely functional programming language?|purely functional]], [[#What is lazy evaluation?|lazy]], [[#What is static typing?|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 [http://en.wikipedia.org/wiki/Haskell_Curry Haskell Curry]
 
 
== Functions ==
 
 
=== How do i apply functions? ===
 
TODO
 
 
=== What is partial application? ===
 
 
{| class="wikitable"
 
|-
 
! Answer
 
! Example
 
|-
 
|By passing less than the full set of arguments to a function, one can create new functions.
 
|With the function
 
<haskell>
 
add :: Int -> Int -> Int
 
add x y = x + y
 
</haskell>
 
that adds two numbers, we can define another function
 
<haskell>
 
addOne = add 1
 
</haskell>
 
that adds 1 to any given number.
 
|}
 
 
=== What is the "Prelude"? ===
 
 
The Prelude is a standard module that is available to all Haskell code by default.
 
 
=== What is currying? ===
 
TODO
 
 
=== How do i define a function? ===
 
 
{| class="wikitable"
 
|-
 
! Answer
 
! Example
 
|-
 
|TODO
 
|<haskell>add x y = x + y</haskell>
 
|}
 
 
Didn't you say Haskell is statically typed?
 
It is. TODO
 
 
=== What is an infix operator? ===
 
 
{| class="wikitable"
 
|-
 
! Answer
 
! Example
 
|-
 
|Infix operators are normal functions.
 
 
TODO: symbols, round brackets
 
|<haskell>5 + 2</haskell>
 
is the same as
 
<haskell>(+) 5 2</haskell>
 
|}
 
 
 
=== Are there any prefix operators? ===
 
 
TODO: (-)
 
 
=== What is point-free style? ===
 
 
{| class="wikitable"
 
|-
 
! 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
 
<haskell>takeFive x = take 5 x</haskell>
 
is
 
<haskell>takeFive = take 5</haskell>
 
|}
 
 
=== What is a higher-order function? ===
 
TODO
 
 
=== What is pattern matching? ===
 
TODO
 
 
== Data types ==
 
TODO
 
 
=== Lists ===
 
TODO
 
 
=== Strings ===
 
TODO
 
 
=== Tupels ===
 
TODO
 
 
=== Tuples ===
 
 
=== Defining your own types ===
 
 
== Type classes ==
 
 
=== What is a type variable? ===
 
TODO
 
 
=== What is a type class? ===
 
TODO
 
 
== Comments ==
 
 
=== How do one write single-line comments? ===
 
 
{| class="wikitable"
 
|-
 
! 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.
 
|<haskell>-- Sort the list
 
sort [3,2,4]
 
</haskell>
 
or
 
<haskell>sort [3,2,4] -- Sort the list</haskell>
 
|}
 
 
=== How do one write block comments? ===
 
{| class="wikitable"
 
|-
 
! Answer
 
! Examples
 
|-
 
|Everything between "'''{-'''" followed by a '''space''' and "'''-}'''" is a block comment.
 
A block comment will be ignored by the compiler.
 
|<haskell>
 
{-
 
The next line would sort the list, if it wasn't in a block comment
 
sort [3,2,4]
 
-}
 
</haskell>
 
or
 
<haskell>sort [3,2,4] {- Block quotes can also be used for single line comments -}</haskell>
 
|}
 
 
== Special characters, expressions and keywords ==
 
 
=== . ===
 
 
{| class="wikitable"
 
|-
 
! Meaning
 
! Example
 
|-
 
|The dot "." is used to compose functions in [[#What is point-free style? |point-free style]], similar to "[[#$|$]]".
 
|<haskell>foo = h . g . f</haskell>
 
is the same as
 
<haskell>foo x = h $ g $ f x</haskell>
 
which is the same as
 
<haskell>foo x = h (g (f x))</haskell>
 
|}
 
 
=== ` ===
 
 
{| class="wikitable"
 
|-
 
! Meaning
 
! Example
 
|-
 
|A function enclosed in back ticks "`" can be used as an [[#What is an infix operator?|infix operator]].
 
|<haskell>2 `subtract` 10</haskell>
 
is the same as
 
<haskell>subtract 2 10</haskell>
 
|}
 
 
=== ' ===
 
Tick TODO: single characters, common usage in function names
 
 
=== : ===
 
 
{| class="wikitable"
 
|-
 
! Meaning
 
! Example
 
|-
 
|The colon ":" is an [[#What is an infix operator?|infix operator]] that adds an element to the beginning of a list.
 
|<haskell>1 : [2,3]</haskell>
 
will result in the new list
 
<haskell>[1,2,3]</haskell>
 
|}
 
 
=== :: ===
 
The double colon TODO
 
 
=== | ===
 
Downslash TODO: pattern matching, data types, Functional dependencies
 
 
=== \ ===
 
Backslash
 
TODO: multiline strings, lambda function
 
 
=== $ ===
 
 
{| class="wikitable"
 
|-
 
! Meaning
 
! Example
 
|-
 
|The dollar sign "$" is a way to compose functions, without typing too many brackets.
 
|<haskell>foo x = h $ g $ f x</haskell>
 
is the same as
 
<haskell>foo x = h (g (f x))</haskell>
 
|}
 
 
=== @ ===
 
TODO: as-pattern
 
 
=== -- ===
 
 
{| class="wikitable"
 
|-
 
! Meaning
 
! Example
 
|-
 
|The double dash "--" followed by a space begins a [[#How do one write single-line comments?|single-line comment]].
 
|<haskell>-- A single-line comment</haskell>
 
|}
 
 
=== [ ] ===
 
The square brackets TODO
 
 
=== {- -} ===
 
 
{| class="wikitable"
 
|-
 
! Meaning
 
! Example
 
|-
 
|Everything between "{-" followed by a space and "-}" is a [[#How do one write block comments?|block comment]].
 
|<haskell>{-
 
This is a block comment
 
-}</haskell>
 
|}
 
 
=== {-# #-} ===
 
{| class="wikitable"
 
|-
 
! Meaning
 
! Example
 
|-
 
|Everything between "{-#" followed by a space and "#-}" defines a compiler pragma.
 
|<haskell>
 
{-# INCLUDE "foo.h" #-}
 
</haskell>
 
|}
 
 
=== data ===
 
 
{| class="wikitable"
 
|-
 
! Meaning
 
! Example
 
|-
 
|
 
"data" defines a new data type. TODO
 
|
 
<haskell>data colors = Red | Blue | Green</haskell>
 
|}
 
 
=== deriving ===
 
TODO
 
 
=== forall ===
 
TODO
 
 
=== newtype ===
 
TODO
 
 
=== type ===
 
TODO
 

Latest revision as of 15:52, 19 February 2010