Difference between revisions of "User:Lenny222/Haskell explained to the busy"
Jump to navigation
Jump to search
(→Basics) |
|||
(79 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 == |
||
− | {| class="wikitable" |
||
− | |- |
||
− | |||
− | ! Question |
||
− | ! Answer |
||
− | |- |
||
− | |What is Haskell? |
||
− | | Haskell is a purely functional, lazy, statically typed programming language |
||
− | |- |
||
− | |What is a '''purely functional''' programming language? |
||
− | | TODO |
||
− | |- |
||
− | |What is good about a purely functional programming language? |
||
− | | TODO |
||
− | |- |
||
− | |What is a '''lazy''' programming language? |
||
− | | TODO |
||
− | |- |
||
− | |What is good about a lazy programming language? |
||
− | | TODO |
||
− | |- |
||
− | |What is a '''statically typed''' programming language? |
||
− | | TODO |
||
− | |- |
||
− | |What is good about a statically typed programming language? |
||
− | | TODO |
||
− | |- |
||
− | |Is Haskell '''Open Source'''? |
||
− | | TODO |
||
− | |- |
||
− | |Why the name '''"Haskell"'''? |
||
− | | Haskell is named after the American mathematician [http://en.wikipedia.org/wiki/Haskell_Curry Haskell Curry] |
||
− | |} |
||
− | |||
− | == Basics == |
||
− | {| class="wikitable" |
||
− | |- |
||
− | ! Question |
||
− | ! Answer |
||
− | |- |
||
− | |What is the meaning of the '''double colon''' "'''::'''"? |
||
− | |TODO |
||
− | |- |
||
− | |What is the meaning of the '''square brackets''' "'''['''" and "''']'''"? |
||
− | | TODO |
||
− | |- |
||
− | |What is the meaning of the '''colon''' "''':'''"? |
||
− | |":" is an infix operator that adds an element to the beginning of a list |
||
− | For example: |
||
− | <haskell>1 : [2,3]</haskell> |
||
− | will result in the new list |
||
− | <haskell>[1,2,3]</haskell> |
||
− | |- |
||
− | |What is an '''infix operator'''? |
||
− | | Infix operators are normal functions. TODO: symbols, round brackets |
||
− | For example: |
||
− | <haskell>5 + 2</haskell> |
||
− | is the same as |
||
− | <haskell>(+) 5 2</haskell> |
||
− | |- |
||
− | |Are there any '''prefix operators'''? |
||
− | |TODO |
||
− | |- |
||
− | |What is the meaning of the '''backticks''' "'''`'''"? |
||
− | | A function enclosed in "`"s can be used as an infix operator. |
||
− | For example: |
||
− | <haskell>subtract 2 10</haskell> |
||
− | is the same as |
||
− | <haskell>2 `subtract` 10</haskell> |
||
− | |- |
||
− | |How do you '''define a function''' in Haskell? |
||
− | | TODO |
||
− | For example: |
||
− | <haskell>add x y = x + y</haskell> |
||
− | |- |
||
− | |Didn't you say Haskell is statically typed? |
||
− | | It is. TODO |
||
− | |- |
||
− | |What is the meaning of 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: |
||
− | <haskell>-- Sort the list |
||
− | sort [3,2,4] |
||
− | </haskell> |
||
− | or |
||
− | <haskell>sort [3,2,4] -- Sort the list</haskell> |
||
− | |- |
||
− | |What is the meaning of "'''{-'''" and "'''-}'''"? |
||
− | |"{- " (a trailing space is necessary) and "-}" define a '''block comment'''. Everything in between will be ignored by the compiler. |
||
− | For example: |
||
− | <haskell> |
||
− | {- |
||
− | The next line would sort the list, if it wasn't in a block comment |
||
− | sort [3,2,4] |
||
− | -} |
||
− | </haskell> |
||
− | |- |
||
− | |What is the meaning of the '''dollar sign''' "'''$'''"? |
||
− | |"$" is a way to compose functions, but avoid typing too many brackets. |
||
− | For example: |
||
− | <haskell>foo x = h (g (f x))</haskell> |
||
− | is the same as |
||
− | <haskell>foo x = h $ g $ f x</haskell> |
||
− | |- |
||
− | |What is the meaning of the '''dot''' "'''.'''"? |
||
− | |"." is used to compose functions in point-free style, similar to "$". |
||
− | For example: |
||
− | <haskell>foo x = h $ g $ f x</haskell> |
||
− | is the same as |
||
− | <haskell>foo = h . g . f</haskell> |
||
− | |- |
||
− | |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: |
||
− | <haskell>takeFive x = take 5 x</haskell> |
||
− | is the same as |
||
− | <haskell>takeFive = take 5</haskell> |
||
− | in point-free style. |
||
− | |- |
||
− | |What is the meaning of "'''data'''"? |
||
− | | "data" defines a new data type. TODO |
||
− | For example: |
||
− | <haskell>data colors = Red | Blue | Green</haskell> |
||
− | |- |
||
− | |What is the meaning of "'''deriving'''"? |
||
− | | TODO |
||
− | |- |
||
− | |What is the meaning of "'''newtype'''"? |
||
− | | TODO |
||
− | |- |
||
− | |What is the meaning of "'''type'''"? |
||
− | | TODO |
||
− | |- |
||
− | |What is '''currying'''? |
||
− | | TODO |
||
− | |- |
||
− | |What is '''pattern matching'''? |
||
− | | TODO |
||
− | |- |
||
− | |What is the meaning of the backslash "'''\'''"? |
||
− | | TODO: multiline strings, lambda function |
||
− | |} |
||
− | |||
− | == Advanced == |
||
− | |||
− | {| class="wikitable" |
||
− | |- |
||
− | ! Question |
||
− | ! Answer |
||
− | |- |
||
− | |What is the meaning of "'''{-#'''" and "'''#-}'''"? |
||
− | |"{-# " (the trailing space is necessay) and "#-}" define '''compiler pragmas'''. TODO |
||
− | |- |
||
− | |What is a '''Monad'''? |
||
− | |TODO |
||
− | |- |
||
− | |What is the meaning of "'''forall'''"? |
||
− | |TODO |
||
− | |} |