Brett
Brett

Reputation: 330

Generics with interfaces in F#

In C# one can state that a generic parameter must implement a certain interface like so:

public class Something<T> where T : IComparable
{
    ...
}

How does one specify this in F#?

Upvotes: 8

Views: 1009

Answers (1)

MichaelGG
MichaelGG

Reputation: 10006

Generic constraints use "when" in F#:

type Foo<'a when 'a :> IComparable> = 
  member x.Bla = 0

Upvotes: 10

Related Questions