Debian Codegraph @

importers/ding2tei/doc/haskell_intro

raw
1 A very small crash course into Haskell, to allow for a basic understanding of
2 (hopefully) most of the code.
3
4 Think of everything as a mathematical function or simple value (a function with
5 zero arguments).
6 The whole program is one complex function, composed of smaller ones.
7
8 There are also `data' definitions though, these can be considered classes in
9 the mathematical sense and are similar to C-structs.
10
11
12 Further notes
13 - Nesting & indentation
14 - nesting is (usually) achieved via indentation, like in Python.
15 - spaces are used for indentation
16 - line continuations require nothing but further indentation
17
18 - Functions
19 - Functions take one argument.
20 - No parantheses are (normally) required (e.g., 'sqrt 2').
21 - The class of functions from A to B is written as `A -> B'.
22 - Frequently, there are functions of type `A -> (B -> C)', also written as
23 `A -> B -> C' (`->' is right-associative). Such functions are usually
24 to be understood as taking two arguments (of type A and B).
25 - This is possible due to the isomorphism between `A -> (B -> C)'` and
26 `A x B -> C'.
27 - This can easily be generalized for an arbitrary number of arguments.
28 - It is quite common that arguments to functions are functions themselves.
29
30 Function composition
31 - `f . g' is the function that maps `x' to `f(g(x))'.
32
33 - Type annotations
34 - Types may be annotated as follows: `value :: type'.
35
36 - Syntactic sugar
37 - `$'
38 - Usually, one can think of everything on the current nesting level after
39 (and before) `$' as enclosed in parantheses.
40 - e.g.: (2 + (sqrt (2 + 3))) == (2 + (sqrt $ 2 + 2))
41 - multiple `$': (f $ g $ h) = (f (g (h)))
42 - More precisely: `$' is a right associative operator with lowest
43 precedence.
44 - (`$' is in fact not syntactic sugar, but the identity function)
45
46 - Documentation / Troubleshooting
47 - Use Hoogle (sic!) [0] !
48 - Haskell Wiki [1]
49 - Many more resources: [2]
50
51
52 See also:
53 - https://wiki.haskell.org/How_to_read_Haskell
54
55 References:
56 [0] https://hoogle.haskell.org/
57 [1] https://wiki.haskell.org/
58 [2] https://www.haskell.org/documentation/