This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In


    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.