dotnet / dotnet/vblang

Simple syntax for partial application

Open
#441 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
328
Forks
71
PR merge metrics
No merged PRs in 30d

Description

Often I want to partially apply a method, which is clumsy in VB because you have to declare all the other parameters and pass them along:
```vb
Function Foo(bar As String, baz As Integer, qux As Boolean, quux As Date)
...
End Function

Dim partiallyAppliedFoo = Function(baz As Integer, qux As Boolean, quux As Date) Foo("predefinedBar", baz, qux, quux)
Dim result = partiallyAppliedFoo(1, True, Now)
```
Can we add a partially-apply operator? Maybe `...`
```vb
Dim partiallyAppliedFoo = Foo("predefinedBar", ...)
Dim result = partiallyAppliedFoo(1, True, Now)
```

Or maybe we should use the Partial keyword to make it clear to new users.
```vb
Dim partiallyAppliedFoo = Partial Foo("predefinedBar", ...)
```
We probably don't even need the ellipsis anymore:
```vb
Dim partiallyAppliedFoo = Partial Foo("predefinedBar")
```
(Since we're in VB, the Partial keyword will also make things more clear for `Sub`s, which don't return a value and so can't be used in an expression, and so `Dim x = FooSub(oneValue, ...)` looks somewhat awkward, since it isn't clear that here the partial application yields a value (delegate), whereas `Dim x = Partial FooSub(oneArg) is much more clear.

(N.B. If you aren't familiar with partial application or why anyone would want to use it, feel free to read up on it; sorry I haven't had the time to explain or motivate over here.)
(N.B.B. The TypeScript team took the approach of strongly-typing JS's existing `arguments` array as a tuple, then using ES6's existing rest operator to pass them along in the right spot, but I'm not sure this is worth doing for VB. This way is much simpler.)

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.