baronfel / fsharp-lang-testbed

0 stars 0 forks source link

Optionally relax signatures of -X, sin X, cos X to allow use w.r.t. subtyping #23

Open baronfel opened 7 years ago

baronfel commented 7 years ago

Idea 11356425: Optionally relax signatures of -X, sin X, cos X to allow use w.r.t. subtyping

Status : planned

Submitted by Don Syme on 1/8/2016 12:00:00 AM

3 votes

See https://github.com/Microsoft/visualfsharp/issues/799 type Base(x : int) = member self.X = x static member (~-) (a : Base) = Base(-a.X) static member (+) (a : Base, b : Base) = Base(a.X + b.X) static member Cos(a : Base) = Base(2*a.X) type Derived(x : int) = inherit Base(x) let a = Base(1) let minusa = -a // OK let cosa = cos a // OK let twoa = a + a // OK let b = Derived(1) let minusb = -b // Compile error let cosb = cos b // Compile error let twob = b + b // OK