5
爲什麼在這種情況下內聯不起作用?爲什麼這個元組內聯不起作用?
type TupleBuilder() =
static member inline Cons(a,(b,c)) = (a, b, c)
static member inline Cons(a,(b,c,d)) = (a, b, c, d)
static member inline Cons(a,(b,c,d,e)) = (a, b, c, d, e)
let inline cons h t = TupleBuilder.Cons(h,t)
至TupleBuilder.Cons
調用給我下面的編譯器錯誤
A unique overload for method 'Cons' could not be determined based on type
information prior to this program point. A type annotation may be needed.
Candidates:
static member TupleBuilder.Cons : a:'a0 * ('a1 * 'a2 * 'a3 * 'a4) -> 'a0 * 'a1 * 'a2 * 'a3 * 'a4,
static member TupleBuilder.Cons : a:'a0 * ('a1 * 'a2 * 'a3) -> 'a0 * 'a1 * 'a2 * 'a3,
static member TupleBuilder.Cons : a:'a0 * ('a1 * 'a2) -> 'a0 * 'a1 * 'a2
編譯器如何知道'cons'函數中't'有多少個元素?沒有看到使用情況,它不知道「t」是2元組,3元組還是4元組。 – rmunn
通常情況下,「內聯」有助於將決定延遲到呼叫站點。但不在這裏。所以我想知道 – robkuz