Overloaded inline operators in F#: ( |+| )

f#, operator-overloading, syntax

Solution

type Overloads = Overloads with
    static member ($) (Overloads, m1: #IMeasurable) = fun (m2: #IMeasurable) -> m1.Measure + m2.Measure 
    static member ($) (Overloads, m1: int) = fun (m2: #IMeasurable) -> m1 + m2.Measure

let inline ( |+| ) m1 m2 = (Overloads $ m1) m2

Not tested, since I don't have IMeasurable, but it may do the job.

Problem

I'm trying to define an overloaded operator, e.g. `|+|`, as the following: ``` let inline ( |+| ) (m1 : #IMeasurable) (m2 : #IMeasurable) = m1.Measure + m2.Measure ``` The problem is, I can't do something like: ``` let three = m1 |+| m2 |+| m3 ``` Because the operator `|+|` isn't defined for the case `(m1 : int) (m2 : #IMeasurable)`. Is there a way to overload this operator or use static type constraints to make the above expression possible? Is there a way to modify `IMeasurable` (which I can edit) so that this is possible? Anything else that would allow the above expression to work? Thank you.

Original source