Join egghead, unlock knowledge.

Want more egghead? It's 45% off for a limited time only!

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock All Content for 45% Off

Already subscribed? Sign In

Save 45% for a limited time.

Get access to all courses and lessons on egghead today.


    Pattern Match Expressions with Elm's Boolean Type

    Enrico BuonannoEnrico Buonanno

    Unlike many languages, Booleans in Elm are just a plain union type.

    Follow along at



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson


    00:00 Union types play a very big role in Elm's core libraries. A very common union type to use is boolean. The boolean type is just defined like this, and this is it. There's nothing special about booleans. It's not a primitive type. It's just a union type that has the two possible values, true or false.

    00:20 As a result, we can use booleans, for example, in pattern matching expressions. For example, if I wanted to have a render function from bool to string, so render would take a boolean, and then it could return, if the boolean is true, the string yep, and if it's false, then nah.

    00:46 Let me just comment this out so it doesn't conflict with existing bool type, and I could now change the main function to instead display a render for true. You could see that this compiles and renders yep as expected.