Hacker News new | ask | show | jobs
by int_19h 1414 days ago
> It's pretty tricky to do that in an untyped language.

If you mean dynamically typed, then Elixir has it:

https://elixir-lang.org/getting-started/case-cond-and-if.htm...

1 comments

From a quick scroll, that seems to be just C-style `select` with `if` guards?

What I was referring to is things like `match x { Some(y) => ..., None => ... }`, where there is data that is available only in some variants of the type (like `y`). Without a type, even naming these variants becomes an interesting problem. (Not unsolvable, mind you. But not obvious either, and you lose some of the benefits that algebraic data types have in typed languages.)

No, it matches on the structure of data as well as embedded values. E.g. you can match on %{foo: y} vs %{bar: y}.