fsharp / fsharp/fslang-suggestions

Support type classes or implicits

Open
#243 216 comments 409 reactions 0 assignees View on GitHub
area: srtp-and-constraints await-csharp-alignment old votes:200+
Dominant language
No language data
Stars
373
Forks
21
PR merge metrics
No merged PRs in 30d

Description

NOTE: Current response by @dsyme is here: https://github.com/fsharp/fslang-suggestions/issues/243#issuecomment-916079347

-----

**Submitted by exercitus vir on 4/12/2014 12:00:00 AM**
**392 votes on UserVoice prior to migration**

(Updated the suggestion to "type classes or implicits", and edited it)
Please add support for type classes or implicits. Currently, it's possible to hack type classes into F# using statically resolved type parameters and operators, but it is really ugly and not easily extensible. I'd like to see something similar to an interface declaration:

``` fsharp
class Mappable =
abstract map : ('a -> 'b) -> 'm<'a> -> 'm<'b>
```

Existing types could then be made instances of a type classes by writing them as type extensions:

``` fsharp
type Seq with
class Mappable with
member map = Seq.map

type Option with
class Mappable with
member map = Option.map
```

I know that the 'class' keyword could be confusing for OO-folks but I could not come up with a better keyword for a type class but since 'class' is not used in F# anyway, this is probably less of a problem.

**[Original UserVoice Submission](https://fslang.uservoice.com/forums/245727-f-language/suggestions/5762135)**
[Archived Uservoice Comments](../tree/master/archive/suggestion-5762135-support-for-type-classes-or-implicits.md#comments)

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.