From 87f9126cdb09d93331286f698f17b6a4a472cd94 Mon Sep 17 00:00:00 2001 From: Meatball Date: Fri, 11 Oct 2024 10:45:51 +0200 Subject: [PATCH 1/3] Rework bool concept --- .vscode/tasks.json | 50 +++++++++++ concepts/booleans/.meta/config.json | 3 +- concepts/booleans/about.md | 83 ++++++++++++++++-- concepts/booleans/introduction.md | 85 ++++++++++++++++++- concepts/booleans/links.json | 7 +- .../pacman-rules/.docs/instructions.md | 8 +- .../pacman-rules/.docs/introduction.md | 84 +++++++++++++++++- .../concept/pacman-rules/.meta/config.json | 3 + 8 files changed, 302 insertions(+), 21 deletions(-) create mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..c7efda6e9 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,50 @@ + +{ + // Automatically created by phoityne-vscode extension. + + "version": "2.0.0", + "presentation": { + "reveal": "always", + "panel": "new" + }, + "tasks": [ + { + // F7 + "group": { + "kind": "build", + "isDefault": true + }, + "label": "haskell build", + "type": "shell", + //"command": "cabal configure && cabal build" + "command": "stack build" + }, + { + // F6 + "group": "build", + "type": "shell", + "label": "haskell clean & build", + //"command": "cabal clean && cabal configure && cabal build" + "command": "stack clean && stack build" + //"command": "stack clean ; stack build" // for powershell + }, + { + // F8 + "group": { + "kind": "test", + "isDefault": true + }, + "type": "shell", + "label": "haskell test", + //"command": "cabal test" + "command": "stack test" + }, + { + // F6 + "isBackground": true, + "type": "shell", + "label": "haskell watch", + "command": "stack build --test --no-run-tests --file-watch" + } + ] +} diff --git a/concepts/booleans/.meta/config.json b/concepts/booleans/.meta/config.json index 6fdee8b8e..575d91464 100644 --- a/concepts/booleans/.meta/config.json +++ b/concepts/booleans/.meta/config.json @@ -2,6 +2,7 @@ "blurb": "Booleans are either true or false. They support NOT, AND, and OR operators.", "authors": [ "ErikSchierboom", - "pwadsworth" + "pwadsworth", + "meatball133" ] } \ No newline at end of file diff --git a/concepts/booleans/about.md b/concepts/booleans/about.md index a2d50e84d..cac109dd1 100644 --- a/concepts/booleans/about.md +++ b/concepts/booleans/about.md @@ -1,15 +1,84 @@ -# About +# Bools -The boolean type `Bool` is an enumeration of `True` and `False`. The basic boolean operators are `&&` (and), `||` (or), and `not`. +Haskell has a type known as [`Bool`][bools]. +It is an enumeration of `True` and `False`. + +## Logical operators + +Haskell has three logical operators (`not`, `||`, `&&`), which combine Bools and make expressions that produce different values. + +### And(`&&`) + +The [_and_ operator][and] in Haskell is represented by `&&` and returns `True` if both values are `True`; otherwise, it returns `False`. +When using the _and_ operator, one Bool is placed on the right side of the `&&` and another on the left side. + +```haskell +True && True +-- -> True + +True && False +-- -> False +``` + +### Or(`||`) + +The [_or_ operator][or] in Haskell is represented by `||` and returns `True` if **at least one** of the values given is `True`. +If both of the values are `False`, then it returns `False`. +When using the _or_ operator, one Bool should be placed on the right side of the `||` and another on the left. ```haskell -True || False -- True -True && False -- False +True || True +-- -> True + +True || False +-- -> True + +False || False +-- -> False ``` -The three boolean operators each have a different operator precedence. They are evaluated in this order: `not` first, `&&` second, and finally `||`. If you want to override these rules, you can enclose a boolean expression in parentheses (`()`), as the parentheses have an even higher operator precedence. +### Not(`not`) + +The _not_ operator in Crystal is represented by `not` and returns `True` if the given Bool is `False` and returns `False` if `True` is provided. +When using the _not_ operator, one Bool should be placed after the operator (`not`). ```haskell -not True && False -- False -not (True && False) -- True +not True +-- -> False + +not False +-- -> True ``` + +## Using parentheses(`()`) + +When working with booleans, you can use parentheses to decide which Bools to evaluate first. +The result can differ depending on how the parentheses are used. +In Haskell, what is in parentheses is evaluated first. + +```haskell +True && False && False || True +-- -> True + +True && False && (False || True) +-- -> False +``` + +Since what is in parentheses is evaluated first, the _not_ operator will apply to the expression inside parentheses in the following example. + +```haskell +not True && False +-- -> False + +not (True && False) +-- -> True +``` + +~~~~exercism/note +You should only use parentheses when they affect the result; otherwise, they should be omitted. +~~~~ + +[bools]: https://hackage.haskell.org/package/base/docs/Data-Bool.html +[and]: https://hackage.haskell.org/package/base/docs/Prelude.html#v:-38--38- +[or]: https://hackage.haskell.org/package/base/docs/Prelude.html#v:-124--124- +[not]: https://hackage.haskell.org/package/base/docs/Prelude.html#v:not diff --git a/concepts/booleans/introduction.md b/concepts/booleans/introduction.md index 4f9e00cee..cac109dd1 100644 --- a/concepts/booleans/introduction.md +++ b/concepts/booleans/introduction.md @@ -1,7 +1,84 @@ -# Introduction +# Bools -Booleans in Haskell are represented by the `Bool` type, which values can be either `True` or `False`. +Haskell has a type known as [`Bool`][bools]. +It is an enumeration of `True` and `False`. -Haskell supports three boolean operators: `not` (NOT), `&&` (AND), and `||` (OR). +## Logical operators -The three boolean operators each have a different operator precedence. They are evaluated in this order: `not` first, `&&` second, and finally `||`. If you want to override these rules, you can enclose a boolean expression in parentheses (`()`), as the parentheses have an even higher operator precedence. +Haskell has three logical operators (`not`, `||`, `&&`), which combine Bools and make expressions that produce different values. + +### And(`&&`) + +The [_and_ operator][and] in Haskell is represented by `&&` and returns `True` if both values are `True`; otherwise, it returns `False`. +When using the _and_ operator, one Bool is placed on the right side of the `&&` and another on the left side. + +```haskell +True && True +-- -> True + +True && False +-- -> False +``` + +### Or(`||`) + +The [_or_ operator][or] in Haskell is represented by `||` and returns `True` if **at least one** of the values given is `True`. +If both of the values are `False`, then it returns `False`. +When using the _or_ operator, one Bool should be placed on the right side of the `||` and another on the left. + +```haskell +True || True +-- -> True + +True || False +-- -> True + +False || False +-- -> False +``` + +### Not(`not`) + +The _not_ operator in Crystal is represented by `not` and returns `True` if the given Bool is `False` and returns `False` if `True` is provided. +When using the _not_ operator, one Bool should be placed after the operator (`not`). + +```haskell +not True +-- -> False + +not False +-- -> True +``` + +## Using parentheses(`()`) + +When working with booleans, you can use parentheses to decide which Bools to evaluate first. +The result can differ depending on how the parentheses are used. +In Haskell, what is in parentheses is evaluated first. + +```haskell +True && False && False || True +-- -> True + +True && False && (False || True) +-- -> False +``` + +Since what is in parentheses is evaluated first, the _not_ operator will apply to the expression inside parentheses in the following example. + +```haskell +not True && False +-- -> False + +not (True && False) +-- -> True +``` + +~~~~exercism/note +You should only use parentheses when they affect the result; otherwise, they should be omitted. +~~~~ + +[bools]: https://hackage.haskell.org/package/base/docs/Data-Bool.html +[and]: https://hackage.haskell.org/package/base/docs/Prelude.html#v:-38--38- +[or]: https://hackage.haskell.org/package/base/docs/Prelude.html#v:-124--124- +[not]: https://hackage.haskell.org/package/base/docs/Prelude.html#v:not diff --git a/concepts/booleans/links.json b/concepts/booleans/links.json index 0637a088a..833fe0ed8 100644 --- a/concepts/booleans/links.json +++ b/concepts/booleans/links.json @@ -1 +1,6 @@ -[] \ No newline at end of file +[ + { + "url": "https://hackage.haskell.org/package/base/docs/Data-Bool.html", + "description": "Prelude: Data.Bool" + } +] \ No newline at end of file diff --git a/exercises/concept/pacman-rules/.docs/instructions.md b/exercises/concept/pacman-rules/.docs/instructions.md index 7f16bacf5..63e87659b 100644 --- a/exercises/concept/pacman-rules/.docs/instructions.md +++ b/exercises/concept/pacman-rules/.docs/instructions.md @@ -11,7 +11,7 @@ You have four rules to translate, all related to the game states. Define the `eatsGhost` function that takes two arguments (_whether Pac-Man has a power pellet active_ and _Pac-Man is touching a ghost_) and returns a `Bool` value when Pac-Man is able to eat the ghost. The function should return `True` only when Pac-Man has a power pellet active and is touching a ghost. -```Haskell +```haskell eatsGhost False True -- -> False ``` @@ -21,7 +21,7 @@ eatsGhost False True Define the `scores` function that takes two arguments (_whether Pac-Man is touching a power pellet_ and _Pac-Man is touching a dot_) and returns a `Bool` value if Pac-Man scored. The function should return `True` when Pac-Man is touching a power pellet or a dot. -```Haskell +```haskell scores True True -- -> True ``` @@ -31,7 +31,7 @@ scores True True Define the `loses` function that takes two arguments (_whether Pac-Man has a power pellet active_ and _Pac-Man is touching a ghost_) and returns a `Bool` value if Pac-Man loses. The function should return `True` when Pac-Man is touching a ghost and does not have a power pellet active. -```Haskell +```haskell loses False True -- -> True ``` @@ -41,7 +41,7 @@ loses False True Define the `wins` function that takes three arguments (_whether Pac-Man has eaten all of the dots_, _Pac-Man has a power pellet active_, and _Pac-Man is touching a ghost_) and returns a `Bool` value if Pac-Man wins. The function should return `True` when Pac-Man has eaten all of the dots _and_ has not lost based on the arguments defined in part 3. -```Haskell +```haskell wins False True False -- -> False ``` diff --git a/exercises/concept/pacman-rules/.docs/introduction.md b/exercises/concept/pacman-rules/.docs/introduction.md index 4c1eab40f..388ea4a52 100644 --- a/exercises/concept/pacman-rules/.docs/introduction.md +++ b/exercises/concept/pacman-rules/.docs/introduction.md @@ -1,8 +1,84 @@ # Introduction -Booleans in Haskell are represented by the `Bool` type, which values can be either `True` or `False`. +Haskell has a type known as [`Bool`][bools]. +It is an enumeration of `True` and `False`. -Haskell supports three boolean operators: `not` (NOT), `&&` (AND), and `||` (OR). +## Logical operators -The three boolean operators each have a different operator precedence, which causes them to be evaluated in this order: `not` first, `&&` second, and finally `||`. -If you want to override these rules, you can enclose a boolean expression in parentheses (`()`), as the parentheses have an even higher operator precedence. +Haskell has three logical operators (`not`, `||`, `&&`), which combine Bools and make expressions that produce different values. + +### And(`&&`) + +The [_and_ operator][and] in Haskell is represented by `&&` and returns `True` if both values are `True`; otherwise, it returns `False`. +When using the _and_ operator, one Bool is placed on the right side of the `&&` and another on the left side. + +```haskell +True && True +-- -> True + +True && False +-- -> False +``` + +### Or(`||`) + +The [_or_ operator][or] in Haskell is represented by `||` and returns `True` if **at least one** of the values given is `True`. +If both of the values are `False`, then it returns `False`. +When using the _or_ operator, one Bool should be placed on the right side of the `||` and another on the left. + +```haskell +True || True +-- -> True + +True || False +-- -> True + +False || False +-- -> False +``` + +### Not(`not`) + +The _not_ operator in Crystal is represented by `not` and returns `True` if the given Bool is `False` and returns `False` if `True` is provided. +When using the _not_ operator, one Bool should be placed after the operator (`not`). + +```haskell +not True +-- -> False + +not False +-- -> True +``` + +## Using parentheses(`()`) + +When working with booleans, you can use parentheses to decide which Bools to evaluate first. +The result can differ depending on how the parentheses are used. +In Haskell, what is in parentheses is evaluated first. + +```haskell +True && False && False || True +-- -> True + +True && False && (False || True) +-- -> False +``` + +Since what is in parentheses is evaluated first, the _not_ operator will apply to the expression inside parentheses in the following example. + +```haskell +not True && False +-- -> False + +not (True && False) +-- -> True +``` + +~~~~exercism/note +You should only use parentheses when they affect the result; otherwise, they should be omitted. +~~~~ + +[bools]: https://hackage.haskell.org/package/base/docs/Data-Bool.html +[and]: https://hackage.haskell.org/package/base/docs/Prelude.html#v:-38--38- +[or]: https://hackage.haskell.org/package/base/docs/Prelude.html#v:-124--124- +[not]: https://hackage.haskell.org/package/base/docs/Prelude.html#v:not diff --git a/exercises/concept/pacman-rules/.meta/config.json b/exercises/concept/pacman-rules/.meta/config.json index 0ed04122e..50d0f35b9 100644 --- a/exercises/concept/pacman-rules/.meta/config.json +++ b/exercises/concept/pacman-rules/.meta/config.json @@ -2,6 +2,9 @@ "authors": [ "pwadsworth" ], + "contributors": + ["meatball133"] + , "files": { "solution": [ "src/PacmanRules.hs", From f986803e9001d610386c6269d033280d186fe029 Mon Sep 17 00:00:00 2001 From: meatball Date: Sat, 12 Oct 2024 13:53:30 +0200 Subject: [PATCH 2/3] Remove Crystal mention --- concepts/booleans/about.md | 2 +- concepts/booleans/introduction.md | 2 +- exercises/concept/pacman-rules/.docs/introduction.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/concepts/booleans/about.md b/concepts/booleans/about.md index cac109dd1..1349c6f70 100644 --- a/concepts/booleans/about.md +++ b/concepts/booleans/about.md @@ -39,7 +39,7 @@ False || False ### Not(`not`) -The _not_ operator in Crystal is represented by `not` and returns `True` if the given Bool is `False` and returns `False` if `True` is provided. +The _not_ operator in Haskell is represented by `not` and returns `True` if the given Bool is `False` and returns `False` if `True` is provided. When using the _not_ operator, one Bool should be placed after the operator (`not`). ```haskell diff --git a/concepts/booleans/introduction.md b/concepts/booleans/introduction.md index cac109dd1..1349c6f70 100644 --- a/concepts/booleans/introduction.md +++ b/concepts/booleans/introduction.md @@ -39,7 +39,7 @@ False || False ### Not(`not`) -The _not_ operator in Crystal is represented by `not` and returns `True` if the given Bool is `False` and returns `False` if `True` is provided. +The _not_ operator in Haskell is represented by `not` and returns `True` if the given Bool is `False` and returns `False` if `True` is provided. When using the _not_ operator, one Bool should be placed after the operator (`not`). ```haskell diff --git a/exercises/concept/pacman-rules/.docs/introduction.md b/exercises/concept/pacman-rules/.docs/introduction.md index 388ea4a52..1349c6f70 100644 --- a/exercises/concept/pacman-rules/.docs/introduction.md +++ b/exercises/concept/pacman-rules/.docs/introduction.md @@ -1,4 +1,4 @@ -# Introduction +# Bools Haskell has a type known as [`Bool`][bools]. It is an enumeration of `True` and `False`. @@ -39,7 +39,7 @@ False || False ### Not(`not`) -The _not_ operator in Crystal is represented by `not` and returns `True` if the given Bool is `False` and returns `False` if `True` is provided. +The _not_ operator in Haskell is represented by `not` and returns `True` if the given Bool is `False` and returns `False` if `True` is provided. When using the _not_ operator, one Bool should be placed after the operator (`not`). ```haskell From ba10ec7fbaee441a0b4211accc593e02f4e6e5a7 Mon Sep 17 00:00:00 2001 From: meatball Date: Sat, 12 Oct 2024 13:54:03 +0200 Subject: [PATCH 3/3] Remove vsc file --- .vscode/tasks.json | 50 ---------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index c7efda6e9..000000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,50 +0,0 @@ - -{ - // Automatically created by phoityne-vscode extension. - - "version": "2.0.0", - "presentation": { - "reveal": "always", - "panel": "new" - }, - "tasks": [ - { - // F7 - "group": { - "kind": "build", - "isDefault": true - }, - "label": "haskell build", - "type": "shell", - //"command": "cabal configure && cabal build" - "command": "stack build" - }, - { - // F6 - "group": "build", - "type": "shell", - "label": "haskell clean & build", - //"command": "cabal clean && cabal configure && cabal build" - "command": "stack clean && stack build" - //"command": "stack clean ; stack build" // for powershell - }, - { - // F8 - "group": { - "kind": "test", - "isDefault": true - }, - "type": "shell", - "label": "haskell test", - //"command": "cabal test" - "command": "stack test" - }, - { - // F6 - "isBackground": true, - "type": "shell", - "label": "haskell watch", - "command": "stack build --test --no-run-tests --file-watch" - } - ] -}