12

I'm trying to define operator with the explicit type parameters and constraints:

let inline (===)<'a, 'b
    when 'a : not struct
     and 'b : not struct> a b = obj.ReferenceEquals (a,b)

It works well in F# 2.0, but produces the:

warning FS1189:
Type parameters must be placed directly adjacent to the type name, e.g. "type C<'T>", not type "C <'T>"

So what is the right way to do explicit type arguments specification for operator definition?

p.s. Please don't tell me about implicit type parameters and some other workarounds, I want to solve concretely this issue.

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
controlflow
  • 6,667
  • 1
  • 31
  • 55

2 Answers2

13

A bug in the compiler means that symbolic operators are never considered directly adjacent to type parameters. You can workaround via e.g.

let inline myeq<'a, 'b 
    when 'a : not struct 
    and 'b : not struct> a b = obj.ReferenceEquals (a,b) 

let inline (===) a b = myeq a b
Brian
  • 117,631
  • 17
  • 236
  • 300
4
let inline (===) (a : 'TA when 'TA : not struct) (b : 'TB when 'TB : not struct) = 
    obj.ReferenceEquals (a,b)
Mark H
  • 13,797
  • 4
  • 31
  • 45