Comment by WJW

1 month ago

There are (some) guards available though? You could rewrite your example as:

    case x {
      n if x < 0 -> ...
      n if x > 10 -> ...
      n if x <= 10 -> ...
    }

Guards are a bit limited in that they cannot contain function calls, but that's a problem of the BEAM and not something Gleam could control.

Ah right, I remember now.

> Guards are a bit limited in that they cannot contain function calls,

I feel like that's not a small sacrifice.

> but that's a problem of the BEAM and not something Gleam could control.

Could Gleam desugar to a case expression like I wrote above?

  • Guards also eliminate checking for whether a pattern matching is comprehensive. Or do I remember wrong and the language does not check it at all?