Skip to content

Cannot implement a generic interface with static abstract members with different generic arguments #15713

@Andreas-Dorfer

Description

@Andreas-Dorfer

I'm experimenting with the new System.Numerics namespace and came across an issue with generic interfaces with static abstract members. I cannot implement a generic interface with static abstract members with different generic arguments. In this example, I want to implement IMultiplyOperators<Vector, double, Vector> and IMultiplyOperators<Vector, Vector, Vector>.

open System.Numerics

type Vector = Vector of x: double * y: double * z: double with
    
    //factor
    static member (*) (Vector (x, y, z), f) =
        Vector (x * f, y * f, z * f)

    //cross product
    static member (*) (Vector (x1, y1, z1), Vector (x2, y2, z2)) =
        Vector (y1 * z2 - z1 * y2, z1 * x2 - x1 * z2, x1 * y2 - y1 * x2)

    interface IMultiplyOperators<Vector, double, Vector> with
        static member (*) (a, f) = a * f
    interface IMultiplyOperators<Vector, Vector, Vector> with
        static member (*) (a, b) = a * b

I'm getting the following compiler errors:

Program.fs(13,15): error FS0001: This expression was expected to have type�    'decimal'    �but here has type�    'Vector'
Program.fs(13,15): error FS0001: This expression was expected to have type�    'decimal'    �but here has type�    'Vector'
Program.fs(13,15): error FS0909: All implemented interfaces should be declared on the initial declaration of the type
  • net7.0
  • FSharp.Core 7.0.300
  • Visual Studio 17.6.5
  • MSBuild version 17.6.8+c70978d4d for .NET

VectorTry.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions