Allow multiple base types/interfaces on flexible type annotation #528

Calogyne opened this Issue Dec 30, 2016 · 0 comments


None yet

1 participant

Calogyne commented Dec 30, 2016 edited

Multiple base types/interfaces on flexible type annotation

I propose we provide a more succinct way to write flexible type that's compatible with multiple base types or interfaces.

Currently in F#, doing so requires writing a rather tedious type constraint, for example:

let multipleInterfaces (x: 'a when 'a :> IEquatable<'T> and 'a :> IComparable) = ()
multipleInterfaces 1

//or hacking with type alias
type EquatableAndComparable<'T, 'a when 'a :> IEqutatable<'T> and 'a :> IComparable> = 'a
let multipleInterfaces' (x: EquatableAndComparable<'T, 'a>) = ()
multipleInterfaces' 1

A possible syntax could be:

let multipleInterfaces (x: #(IEquatable<'T> and IComparable)) = ()

Pros and Cons

Pro: This saves some extra typing.
Con: Adds a little more cost to learn the language.

Extra informtion

Estimated cost (XS):

See "Protocol Composition" on

Affadavit (must be submitted)

Please tick this by placing a cross in the box:

  • This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:

  • This is not a breaking change to the F# language design
  • I would be willing to help implement and/or test this
  • I or my company would be willing to help crowdfund F# Software Foundation members to work on this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment