fsharp / fsharp/fslang-suggestions

Allow aliases in interface implementation

Open
#501 11 comments 7 reactions 1 assignee Claimed by @edgarfgp View on GitHub
approved-in-principle needs rfc
Dominant language
No language data
Stars
373
Forks
21
PR merge metrics
No merged PRs in 30d

Description

Consider this F# code:

``` fsharp
type IFoo =
abstract Bar1: int -> int
abstract Bar2: int -> int -> int

type Foo() as this =
interface IFoo with
member x.Bar1 a = this.Bar2 a 0
member x.Bar2 a b = a + b
```

This doesn't compile because `this` doesn't implement IFoo implicitly, still, it is very common to have to reference `this` as a specific interface repeatedly.

The proposal is to add the `as {alias}` optional syntax to the interface implementation in a similar manner it can be added to the type defintion:

``` fsharp
type IFoo =
abstract Bar1: int -> int
abstract Bar2: int -> int -> int

type Foo() as this =
interface IFoo as ifoo with
member x.Bar1 a = ifoo.Bar2 a 0
member x.Bar2 a b = a + b
```
## Pros

Making it less cumbersome to deal with interface implementation while retaining the explicit type conversions semantics.
## Cons

More OO

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.