考慮以下示例代碼,其中我有一個泛型類型和2個靜態成員構造函數,用於創建上述類型的專用實例。爲什麼F#在這種情況下不能推斷出類型?
type Cell<'T> = { slot: 'T }
with
static member CreateInt x : IntCell = { slot = x }
static member CreateString x : StringCell = { slot = x}
and IntCell = Cell<int>
and StringCell = Cell<string>
// Warnings on the next 2 lines
let x = Cell.CreateInt 123
let y = Cell.CreateString "testing"
我想我有必要的類型註釋到位,但F#給了我警告。 E.g:
Warning 2 The instantiation of the generic type 'Cell' is missing and can't be inferred from the arguments or return type of this member. Consider providing a type instantiation when accessing this type, e.g. 'Cell<_>'.
我怎樣才能使警告消失?
提示:您正在使用_generic_類型的靜態成員。 – ildjarn 2014-11-23 20:21:02
@ildjarn你應該發佈作爲答案:-) – 2014-11-23 20:31:25