Difference between revisions of "User:Lenny222/Haskell explained to the busy"
Jump to navigation
Jump to search
(30 intermediate revisions by the same user not shown) | |||
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 you apply functions? === |
||
− | TODO |
||
− | |||
− | === 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 you define a function? === |
||
− | TODO |
||
− | |||
− | {| 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 you 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 you write a block comment? === |
||
− | {| 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> |
||
− | 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>subtract 2 10</haskell> |
||
− | which is the same as |
||
− | <haskell>2 `subtract` 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 |
||
− | |||
− | === \ === |
||
− | 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> |
||
− | |} |
||
− | |||
− | |||
− | === -- === |
||
− | |||
− | {| class="wikitable" |
||
− | |- |
||
− | ! Meaning |
||
− | ! Example |
||
− | |- |
||
− | |The double dash "--" followed by a space begins a [[#How do you write single-line comments?|single-line comment]]. |
||
− | |<haskell>-- A single-line comment</haskell> |
||
− | |} |
||
− | |||
− | === [ ] === |
||
− | The square brackets TODO |
||
− | |||
− | === {- -} === |
||
− | |||
− | {| class="wikitable" |
||
− | |- |
||
− | ! Meaning |
||
− | ! Examples |
||
− | |- |
||
− | |Everything between "{-" followed by a space and "-}" is a [[#How do you write a block comment?|block comment]]. |
||
− | |<haskell>{- |
||
− | This is a block comment |
||
− | -}</haskell> |
||
− | |} |
||
− | |||
− | === {-# #-} === |
||
− | "{-# " (the trailing space is necessay) and "#-}" define '''compiler pragmas'''. TODO |
||
− | |||
− | === data === |
||
− | |||
− | {| class="wikitable" |
||
− | |- |
||
− | ! Meaning |
||
− | ! Examples |
||
− | |- |
||
− | | |
||
− | "data" defines a new data type. TODO |
||
− | | |
||
− | <haskell>data colors = Red | Blue | Green</haskell> |
||
− | |} |
||
− | |||
− | === deriving === |
||
− | TODO |
||
− | |||
− | === forall === |
||
− | TODO |
||
− | |||
− | === newtype === |
||
− | TODO |
||
− | |||
− | === type === |
||
− | TODO |