Skip to content

[Learning Mode] Discussion: How do we best introduce case-expressions? #1102

Open
@kytrinyx

Description

@kytrinyx

The goal of this issue is to come up with a code example that can be used as the basis for an exercise that introduces case-expressions in Haskell.

A few thoughts:

  • We don't have to teach everything about case expressions (and indeed, we probably shouldn't). We'd rather have several smaller exercises that build on each other than one big exercise. This gets people writing code quickly, which helps the concept to start sinking in
  • We'd like to introduce this as early as possible in the concept tree, maybe right after Temperature, which introduces a couple of basic numeric types (Int and Float). But if the example code is easier to do using something other than numbers, then we can introduce another exercise first, before case-expressions.
  • The code doesn't need to be ideal, idiomatic Haskell. This is a tiny stepping stone towards understanding case in Haskell, but students will quickly move beyond this into code that uses more of the language, and uses the language in ways that are more typical.

Elixir introduces case expressions with this exercise:
https://exercism.org/tracks/elixir/exercises/german-sysadmin
The example solution looks like this:
https://github.com/exercism/elixir/blob/main/exercises/concept/german-sysadmin/.meta/exemplar.ex

Is this a bit of code that would translate well into Haskell? (Would it feel like decent Haskell, or would it feel weird and foreign?)

What are some other sample bits of code that use case in a way that is potentially easy to understand for people who are new to Haskell?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions