core-lang / core

The Core Programming Language
https://core-lang.dev
MIT License
45 stars 1 forks source link

pattern matching with `is` #30

Closed soc closed 1 year ago

soc commented 2 years ago

This means that ...

fun describe(pet: Pet): String =
  match pet {
    Cat(name, lives) => "cat $name has $lives lives"
    Dog(name, years) => "dog $name is $years old"
  }

... can be replaced with ...

fun describe(pet: Pet): String =
  if pet
    ... is Cat(let name, let lives) { "cat $name has $lives lives" }
    ... is Dog(let name, let years) { "dog $name is $years old" }

and match removed from the language completely.