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..1349c6f70 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 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 -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..1349c6f70 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 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 +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..1349c6f70 100644 --- a/exercises/concept/pacman-rules/.docs/introduction.md +++ b/exercises/concept/pacman-rules/.docs/introduction.md @@ -1,8 +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, 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 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 +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",