diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000000000000000000000000000000000000..7d3aa8cc1f4012a27a3dcf462dac727c1814e0a8 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,17 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Make", + "type": "shell", + "command": "make", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/src/01-basic-usage.md b/src/01-basic-usage.md index fa56c3c7146946089f279f333151d10154a0de99..3c89d507ac2cdddf1df49ac6bf588265984e561e 100644 --- a/src/01-basic-usage.md +++ b/src/01-basic-usage.md @@ -22,7 +22,7 @@ - `:quit` / `:q`: Close GHCi - `:help` / `:h`/`:?`: Get a list of available commands -**Make sure you can open a file in GHCI!** +**Make sure you can open a file in GHCi!** ## Compiling diff --git a/src/02-what-is-functional-programming.md b/src/02-what-is-functional-programming.md index ed38d14d5ebfa24645e83d59accc726ce230b1af..d4e8a27cfc591c737741b57e919274685107ea05 100644 --- a/src/02-what-is-functional-programming.md +++ b/src/02-what-is-functional-programming.md @@ -3,26 +3,27 @@ ## The Difference - *Imperative* vs. *Functional* -- Programming lanuages like Java or C are imperative -- Imperative: program is list of commands to be executed one after another +- Programming lanuages like Java or C are **imperative** +- Program = sequence of commands to be executed one after another ``` -x = 3 -do_thing(x) -x = x + 4 -y = 2 -do_another_thing(x, y) +x = 2 +doThing(x) +x = 4 +doThing(x) ``` +Works without problem. + ## Functional - Different approach -- In functional programming a program is no list of commands -- More a *collection of definitions* +- In **functional** programming a program is **not** a list of commands +- Program = *collection of definitions* ```haskell -x = 4 x = 2 +x = 4 ``` -What will happen? +Will *this* work? \ No newline at end of file diff --git a/src/03-first-functions.md b/src/03-first-functions.md index fed7e9fcdc131397077d52fd02e77dd4ef07632a..61ebba964592953190fe645945540847453d1565 100644 --- a/src/03-first-functions.md +++ b/src/03-first-functions.md @@ -1,8 +1,19 @@ # First Functions +Let's take a look at some predefined basic functions, how to use them and learn how we can define our first own functions. + +## Defining Values + +`x = 42` defines the variable `x` to hold the value `42`. + +Any variable can only be defined *once*[^ghci_multiple]! + +We can also use truth values: `True` and `False` (*capitalized!*) + +[^ghci_multiple]: Except in GHCi where defining a value again overwrites previous definitions for convenience + ## Basic Calculation -`x = 1` defines `x` to hold the value `1` as already seen. Basic calculations work as expected @@ -15,8 +26,6 @@ Basic calculations work as expected ## Truth values -Truth values: `True` and `False` (*capitalized!*) - - `True && False` - `True || False` - `not False` @@ -30,7 +39,9 @@ Comparisons also work as expected. - `1 >= 10` - `2 /= 2` (note that not `!=`) -## First Functions +## Define our own + +Let's define some functions of our own. ```haskell double x = x * 2 diff --git a/src/04-first-types.md b/src/04-first-types.md index 9f6e1ef3fb34f375077d5e44a83919568aca08e0..dcf1f5b7ea8c31bd958320efe0666d252014013c 100644 --- a/src/04-first-types.md +++ b/src/04-first-types.md @@ -11,7 +11,9 @@ - `Bool`: Truth values (`True`, `False`) (*capitalized!*) - `Char`: Single characters (`'a'`, `'c'`) - `String`: Text (`"Hello"`, `"Cheese sandwich"`) -- `a -> b`: Function with the +- `a -> b`: Function with + - the input type (*domain*) `a` + - the output type (*codomain* or *range*) `b` ## Specifying a Type @@ -29,7 +31,7 @@ double :: Int -> Int double x = x * 2 ``` -Recommendation: Always specify the type. +Recommendation: *Always* specify the type. ## Lists @@ -50,13 +52,17 @@ empty = [] Lists are a *recursive data structure* -A list is always either -- *an empty list* or -- *an element added in front of another list*. +A list is always one of two things: -Adding an element is done with `:` +- *an empty list:* `[]` +- *an element added in front of another list:* `element : list` -`[1,2,3]` is the same as `1 : (2 : (3 : []))` +These are all the same list: + +- `[1, 2, 3]` +- `1 : [2, 3]` +- `1 : (2 : (3 : []))` +- `1 : 2 : 3 : []` ```haskell moreFruits :: [String]