I am trying to define a general addition operator for a wrapper class. So far I have this: (simplified from actual code)
type Wrap<'a> = | Wrap of 'a static member inline (+) (Wrap x, Wrap y) = Wrap (x + y) let inline addSelf x = x + x
and really works:
let i = addSelf (Wrap 1) // returns Wrap 2 let f = addSelf (Wrap 1.) // returns Wrap 2.0
but the following alternative addSelf does not compile
let inline addSelf' (Wrap x) = (Wrap x) + (Wrap x)
gives error FS0193: the type parameter has no restriction 'when (^ a or ^ 15169): (static member (+): ^ a * ^? 15169 β ^? 15170)'
Why doesn't the more limited addSelf work when addSelf works fine? Thank!
generics f # type-constraints type-parameter
TimC Jul 27 '11 at 18:46 2011-07-27 18:46
source share