effekt-lang / effekt-lang/effekt

Lambda Case

Open
#359 0 comments 0 reactions 0 assignees View on GitHub
feature requires-design
Dominant language
Scala
Stars
469
Forks
41
Avg merge
1d 16h
Merged PRs (30d)
23

Description

In functional programming languages it is possible to match on arguments directly without naming them. Consider:

```
data Vec3 = MkVec3 Double Double Double

add : Vec3 -> Vec3 -> Vec3
add (MkVec3 x1 x2 x3) (MkVec3 y1 y2 y3) = MkVec3 (x1 + y1) (x2 + y2) (x3 + y3)
```

The same code in Effekt is more verbose:

```
record Vec3(x1: Double, x2: Double, x3: Double)

def add(x: Vec3, y: Vec3): Vec3 = (x, y) match {
case (Vec3(x1, x2, x3), Vec3(y1, y2, y3)) => Vec3(x1 + y1, x2 + y2, x3 + y3)
}
```

I would like to be able to write the following instead:

```
def add(Vec3, Vec3): Vec3 = {
case (Vec3(x1, x2, x3), Vec3(y1, y2, y3)) => Vec3(x1 + y1, x2 + y2, x3 + y3)
}
```

This communicates that `add` immediately consumes its arguments exactly once. It avoids having to come up with a name for the parameters. This is also a downside, since names are useful for communicating intent.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.