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

From HaskellWiki
Jump to navigation Jump to search
Line 22: Line 22:
   
 
== Basics ==
 
== Basics ==
  +
{| class="wikitable"
 
 
=== What is an infix operator? ===
|-
 
  +
! Question
 
 
Infix operators are normal functions. TODO: symbols, round brackets
! Answer
 
|-
 
|What is an '''infix operator'''?
 
| Infix operators are normal functions. TODO: symbols, round brackets
 
 
For example:
 
For example:
 
<haskell>5 + 2</haskell>
 
<haskell>5 + 2</haskell>
 
is the same as
 
is the same as
 
<haskell>(+) 5 2</haskell>
 
<haskell>(+) 5 2</haskell>
  +
|-
 
|Are there any '''prefix operators'''?
+
=== Are there any prefix operators? ===
  +
|TODO
 
  +
TODO: (-)
|-
 
  +
|How do you '''define a function''' in Haskell?
+
=== How to define a function? ===
| TODO
 
  +
TODO:
  +
 
For example:
 
For example:
 
<haskell>add x y = x + y</haskell>
 
<haskell>add x y = x + y</haskell>
  +
|-
 
|Didn't you say Haskell is statically typed?
+
Didn't you say Haskell is statically typed?
 
| It is. TODO
 
| It is. TODO
  +
|-
 
|What is '''point-free style'''?
+
=== |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.
+
Point-free style is a way to define functions solely as a composition of other functions, leaving out arguments in the definition.
  +
 
For example:
 
For example:
 
<haskell>takeFive x = take 5 x</haskell>
 
<haskell>takeFive x = take 5 x</haskell>
Line 52: Line 52:
 
<haskell>takeFive = take 5</haskell>
 
<haskell>takeFive = take 5</haskell>
 
in point-free style.
 
in point-free style.
|-
 
|What is '''currying'''?
 
| TODO
 
|-
 
|What is '''pattern matching'''?
 
| TODO
 
   
 
=== What is currying? ===
|}
 
  +
 
=== What is pattern matching? ===
  +
   
 
== Advanced ==
 
== Advanced ==
   
 
=== What is a Monad? ===
{| class="wikitable"
 
 
TODO
|-
 
! Question
 
! Answer
 
|-
 
|What is a '''Monad'''?
 
|TODO
 
|-
 
|What is the meaning of "'''forall'''"?
 
|TODO
 
|}
 
   
 
== Special characters, expressions and keywords ==
 
== Special characters, expressions and keywords ==
Line 175: Line 163:
   
 
=== deriving ===
 
=== deriving ===
 
TODO
  +
  +
=== forall ===
 
TODO
 
TODO
   

Revision as of 11:15, 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

Basics

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 to define a function?

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?

What is pattern matching?

Advanced

What is a Monad?

TODO

Special characters, expressions and keywords

.

Meaning Example
The dot "." is used to compose functions in point-free style, similar to "$".
foo = h . g . f

which 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

is the same as

2 `subtract` 10

'

Tick 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

{- -}

Meaning Examples
Everything between "{- " and "-}" is a block comment and will be ignored by the compiler.

Note that the space after "{- " is necessary.

{-
The next line would sort the list, if it wasn't in a block comment
sort [3,2,4]
-}

or

{- Block quotes can also be used for single line comments -}

{-# #-}

"{-# " (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