4
votes

Compiles:

let inline f< ^T when ^T : (static member (<<<) : ^T * int -> ^T) > (x : ^T) = x <<< 1

Does not compile:

let inline f< ^T when ^T : (static member (>>>) : ^T * int -> ^T) > (x : ^T) = x >>> 1

Errors:

  1. Attempted to parse this as an operator name, but failed
  2. Unexpected symbol '>' in member signature. Expected ')' or other token.
  3. A type parameter is missing a constraint 'when ^T : (static member ( >>> ) : ^T * int32 -> ^T)'

Adding spaces doesn't help; this line yields the same compiler errors:

let inline f< ^T when ^T : (static member ( >>> ) : ^T * int -> ^T) > (x : ^T) = x >>> 1

I've searched both the documentation and the specification, to no avail. Is this a bug? Is there some way to include the > characters in the member signature?

2
Looks like a bug to me...kvb

2 Answers

8
votes

Sure looks like a bug. It's ugly, but one workaround is to use the long form of the operator name:

let inline f< ^T when ^T : (static member op_RightShift : ^T * int -> ^T)> (x : ^T) =
    x >>> 1
6
votes

Do you even need an explicit constraint? This works just as well:

let inline f (x: ^T) : ^T = x >>> 1