Mysterious typecheck error in f # (missing when? 12345:> ISomething)

I have a F # snippet that is not printed correctly. I assume that I need to restrict "a1 and" b1 to ISomething, but I don't know how to do this. There are two errors on the bottom line. The use of f and g in RHS is underlined and the error message is read: Type parameter has no "when" restriction? 123456:> ISomething "The only difference is that the message for g contains the mysterious number one higher than that for f. Thank you very much.

type ISomething =
    abstract getint : int

type IOther<'a, 'b> =
    abstract map : ('a->'a1) -> ('b->'b1) -> IOther<'a1, 'b1>

type sometype<'a, 'b when 'a :> ISomething and 'b :> ISomething> (a:'a, b:'b) =

    member this.map (f:'a->'a1) (g:'b->'b1) : sometype<'a1, 'b1> = sometype (f a, g b)

    interface IOther<'a, 'b> with
        member x.map (f:'a->'a1) (g:'b->'b1) = x.map f g :> IOther<'a1,'b1>
+3
source share
1 answer

The problem is that your display function specifically creates an instance sometype.

, IOther<'a, 'b> , , 'a1 'b1 ISomething ( sometype), .

, IOther<'a, 'b> map, :

type IOther<'a, 'b> =
    abstract map<'a, 'b, 'a1, 'b1 when 'a1 :> ISomething and 'b1 :> ISomething> : ('a->'a1) -> ('b->'b1) -> IOther<'a1, 'b1>

, sometime.map , , IOther<'a, 'b> ISomething.

, sometype.map, , .

+3

All Articles