fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

generate missing match cases automatically

Open michaellilltokiwa opened this issue 1 year ago • 4 comments

In some cases we could auto generate missing match cases automatically. Similar thing is already done for else-blocks in if-else expressions. The second example may be more controversial...

ex =>

  a option String := "hello"
  match a
    string String => say string
    # first case results in unit, second case could be generated automatically
    # nil =>


  a option String := "hello"
  match a
    nil => "nil"
    # first case results in String, second case could be generated automatically
    # and return the string

@tokiwa-software/developers opinions please.

michaellilltokiwa avatar Apr 11 '24 08:04 michaellilltokiwa

The first example sounds quite reasonable, but not the second one to me.

maxteufel avatar May 13 '24 06:05 maxteufel

We should have some mechanism to defer error handling, like Rust's ?. operator. Your first case could be achieved using bind:

  a option String := "hello"
  _ := a.bind unit say

Here, the type inference for unit does not work yet and we might want to have an infix operator for bind as well. The second case is already possible via

  a option String := "hello"
  _ := a.or_else "nil"

but we might want to have an operator here as well. Then, we should make sure that the same operations are used consistently in related features like outcome, num_option, etc. For a match statement, I think that it is helpful to have an error for cases that are not covered.

fridis avatar May 13 '24 09:05 fridis

@fridis My example was not good. I used an option but what I had in mind was any arbitrary choice where bind may not be present. A mechanism to defer error handling or more generally defer some operation would be good I think. We may also want to look into zigs defer: https://ziglang.org/documentation/0.8.1/#defer

michaellilltokiwa avatar May 13 '24 09:05 michaellilltokiwa

Some of my earlier thoughts on this are on the design pages

fridis avatar May 13 '24 09:05 fridis