explicitly define Statically Resolved Type Parameters

Answered explicitly define Statically Resolved Type Parameters

  • Monday, January 21, 2013 7:03 PM
     
     

    How to Explicitly define Statically Resolved Type Parameters of an inline function?

    something like this:

     let inline add<^a,^b,^c> (x:^a) (y:^b) :^c = x + y

All Replies

  • Tuesday, January 22, 2013 8:54 PM
    Moderator
     
     Answered Has Code

    You need to do something like:

    let inline add< ^a, ^b, ^c when (^a or ^b) : (static member (+) : ^a * ^b -> ^c)> x y = 
        ((^a or ^b) : (static member (+) : ^a * ^b -> ^c)(x,y))

    Note the following caveats:

    • You need to insert a space before the first occurrence of ^a, since otherwise the compiler can't parse the two characters "<^".
    • I wasn't able to use the (+) operator on the right hand side directly (I got an ugly error message) - I needed to use a member invocation expression instead.  This may be a bug.
    • Marked As Answer by Rainmater Tuesday, January 22, 2013 9:50 PM
    •