Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework Bools concept #1278

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion concepts/booleans/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"blurb": "Booleans are either true or false. They support NOT, AND, and OR operators.",
"authors": [
"ErikSchierboom",
"pwadsworth"
"pwadsworth",
"meatball133"
]
}
83 changes: 76 additions & 7 deletions concepts/booleans/about.md
Original file line number Diff line number Diff line change
@@ -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
85 changes: 81 additions & 4 deletions concepts/booleans/introduction.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion concepts/booleans/links.json
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
[]
[
{
"url": "https://hackage.haskell.org/package/base/docs/Data-Bool.html",
"description": "Prelude: Data.Bool"
}
]
8 changes: 4 additions & 4 deletions exercises/concept/pacman-rules/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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
```
Expand All @@ -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
```
Expand All @@ -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
```
86 changes: 81 additions & 5 deletions exercises/concept/pacman-rules/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions exercises/concept/pacman-rules/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"authors": [
"pwadsworth"
],
"contributors":
["meatball133"]
,
"files": {
"solution": [
"src/PacmanRules.hs",
Expand Down
Loading