Skip to content

0011: Email Tutorials Haskell For Beginners – Boolean Logic Basics in Haskell

Bernard Sibanda edited this page Dec 9, 2025 · 3 revisions

LigerLearn Video 11

📑 Table of Contents

  • 11.1. Boolean Values in Haskell
  • 11.2. Equality and Inequality Operators
  • 11.3. Comparison Operators
  • 11.4. Logical AND (&&) and Logical OR (||)
  • 11.5. Truth Tables and Combined Expressions
  • 11.6. Boolean Negation with not
  • 11.7. A Walkthrough of a More Complex Boolean Expression
  • 11.8. Glossary of Terms for This Lesson

11.1. Boolean Values in Haskell

Boolean logic answers questions about what is true and what is false. In Haskell, the type responsible for Boolean values is:

Bool

Bool has exactly two valid values: True and False. These two values are at the core of all logical operations in Haskell. Every comparison, conditional, or logical combination ultimately produces a Bool.

11.2. Equality and Inequality Operators

The first category of Boolean functions involves testing equality.

Equality (==)

The operator == compares two values and returns True if they are equal, False otherwise.

Examples:

  • 2 == 2True
  • "hello" == "world"False

Inequality (/=)

The operator /= checks for not equal, returning True when values differ.

Examples:

  • 3 /= 3False
  • 2 /= 3True

The symbol resembles the mathematical “≠” sign, which isn't available on keyboards, so Haskell uses a forward slash plus equals.

11.3. Comparison Operators

The second category involves ordering comparisons, which apply to values that have a meaningful order—numbers, characters, strings, etc.

Common comparison operators:

Operator Meaning
< less than
<= less than or equal
> greater than
>= greater than or equal

Examples from the lesson:

  • 512 < 1024True
  • 1.24 <= 2True (the transcript incorrectly said False, but mathematically it is True)
  • 256 > 32.25True
  • "a" >= "b"False because "a" comes before "b" alphabetically

All these comparisons yield Bool values.

11.4. Logical AND (&&) and Logical OR (||)

Once you produce Booleans, you can combine them:

Logical AND (&&)

  • Only True && True results in True.
  • Any False makes the whole expression False.

Logical OR (||)

  • Only False || False results in False.
  • Any True produces True.

These operators allow you to build complex Boolean conditions.

11.5. Truth Tables and Combined Expressions

To reason about combinations, a truth table is useful.

For variables x and y, each being True or False:

| x | y | x && y | x || y | | ----- | ----- | ------ | ------ | | True | True | True | True | | True | False | False | True | | False | True | False | True | | False | False | False | False |

This table helps you predict what an expression involving AND/OR will evaluate to.

11.6. Boolean Negation with not

The final Boolean operation covered is negation.

not True  -> False
not False -> True

The not function takes a single Bool and flips it.

11.7. A Walkthrough of a More Complex Boolean Expression

The lesson concludes with more challenging examples to test understanding.

Example 1

m = not (True && j)

Given that j is False:

  • True && FalseFalse
  • not FalseTrue

So m = True.

Example 2

n = not False && True

Step-by-step:

  • not FalseTrue
  • True && TrueTrue

So n = True.

Example 3

o = False || not (not h) || not i

Given:

  • h = False
  • i = True

Evaluate:

  • not hTrue
  • not (not h)False
  • not iFalse

Expression becomes:

False || False || False

So:

o = False

These evaluations show how combining AND, OR, and NOT—with nested parentheses—can produce increasingly complex expressions, all reducible step-by-step.

11.8. Glossary of Terms for This Lesson

  • Bool The Boolean type in Haskell with exactly two values: True and False.

  • Equality operator (==) Returns True when two values are equal.

  • Inequality operator (/=) Returns True when two values differ.

  • Comparison operators (<, <=, >, >=) Operators used to compare orderable values, producing Bool.

  • Logical AND (&&) Produces True only when both operands are True.

  • Logical OR (||) Produces True when at least one operand is True.

  • Negation (not) Flips a Boolean value.

  • Truth table A table showing the results of Boolean operations for all input combinations.

  • Orderable types Types with a defined ordering, such as numbers, characters, and strings.

  • Boolean expression Any expression whose final result is a Bool.

Quizz & Progress Badge NFT

Clone this wiki locally