#light
type 'a A =
interface
abstract member A : unit -> 'a
end
let x = { new int A with member x.A() = 1 } // ALLOWED
let y = { new unit A with member x.A() = () } // ERROR?
Yes, unit return types are special (they translate to void) and interact badly with generic code like you have above. We (Credit Suisse) discovered this and reported it to the F team a few weeks ago, but there's no promise of a direct solution because unit return type -> void is an important performance guarantee. The workaround, if I recall correctly, is to use brackets to turn A into a value rather than a function: abstract member A : (unit -> 'a).
Yes, unit return types are special (they translate to void) and interact badly with generic code like you have above. We (Credit Suisse) discovered this and reported it to the F team a few weeks ago, but there's no promise of a direct solution because unit return type -> void is an important performance guarantee. The workaround, if I recall correctly, is to use brackets to turn A into a value rather than a function: abstract member A : (unit -> 'a).
ReplyDeleteThanks, hsenag! The workaround makes sense.
ReplyDelete