Why is this inlining for tuples not working?

Why does the attachment not work in this case?

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 ht = TupleBuilder.Cons(h,t) 

Calling TupleBuilder.Cons gives me the following compiler error

 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 
+5
source share
1 answer

Only embedding does not delay the decision to overload the call site. You need to add type A or type B when calling overload.

You can do this easily using the binary operator in this case:

 type TupleBuilder () = static member inline ($) (_:TupleBuilder, (b,c)) = fun a -> (a, b, c) static member inline ($) (_:TupleBuilder, (b,c,d)) = fun a -> (a, b, c, d) static member inline ($) (_:TupleBuilder, (b,c,d,e)) = fun a -> (a, b, c, d, e) let inline cons ht = (TupleBuilder() $ t) h // val inline cons : h:'a -> t: ^b -> 'c when (TupleBuilder or ^b) : (static member ( $ ) : TupleBuilder * ^b -> 'a -> 'c) 

For more fun tuple fun, check out this old blog post .

+7
source

Source: https://habr.com/ru/post/1272341/


All Articles