Skip to content

Allow indentation and braces (instead of ->) in match clauses #624

@osa1

Description

@osa1

Currently handler and match are somewhat similar in that they specify which operator or value constructor they match, and on the right-hand side what to do with them, but the syntax for them are not exactly the same, which looks inconsistent.

Consider:

fun untry_(ex: either<string, a>): <exn_> a
  match ex
    Right(x) -> x
    Left(exn) -> throw_(exn)

val try_ = handler
  return(x) -> Right(x)
  ctl throw_(exn: string) -> Left(exn)

Here both handler and match use ->.

In handler, I can also indent the right-hand side and omit ->:

// also works
val try_ = handler
  return(x)
    Right(x)

  ctl throw_(exn: string)
    Left(exn)

But I can't do the same in match:

// syntax error
fun untry_(ex: either<string, a>): <exn_> a
  match ex
    Right(x)
      x

    Left(exn)
      throw_(exn)

Since indentation is just braces omitted, I can also use braces in handler if I want to define a handler in one line:

// also works
val try_ = handler
  return(x) { Right(x) }
  ctl throw_(exn: string) { Left(exn) }

Which also doesn't work for match.

I suggest we get rid of -> in match and use braces. That would make the syntax consistent with handler, and allow for cleaner match expressions when the right-hand sides are indented.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions