F# explicit member constraints: The type variable ^T could not be generalized because it would escape its scope

后端 未结 3 1100
孤独总比滥情好
孤独总比滥情好 2020-12-07 01:45

I\'m attempting to use explicit member constraints in F#. The documentation says \"F# supports the complete set of constraints that is supported by the common language runti

3条回答
  •  春和景丽
    2020-12-07 02:13

    Member constrains need statically resolved type parameters. But statically resolved type parameters are not allowed on types (as in your example), only for inline functions and inline methods.

    The underlying problem is probably that types as a whole cannot be inline.

    See also: http://msdn.microsoft.com/en-us/library/dd548046.aspx

    If you use an inline member like this:

    type MyType() =
        member inline this.F a b = a + b
    

    the types of a and b will automatically be correctly constrained.

提交回复
热议问题