тернарный оператор (?<-) (за счёт того, что операторы в фшарпе сами задают srtp констреинты), но вручную
type AppendOp = AppendOp with
static member Append(AppendOp, xs1: 'a array, xs2: 'a array): 'a array =
Array.append xs1 xs2
static member Append(AppendOp, xs1: 'a list, xs2: 'a list): 'a list =
List.append xs1 xs2
#nowarn "0064" // This construct causes code to be less generic than indicated by the type annotations. The type variable 'b has been constrained to be type 'AppendOp'.
let inline append (xs1: 'a) (xs2: 'a) : 'a =
((^b or 'a): (static member Append: ^b * 'a * 'a -> 'a) (AppendOp, xs1, xs2))
append [ 1..3 ] [ 27..30 ] |> printfn "%A"
append [| 1..3 |] [| 27..30 |] |> printfn "%A"
без ворнингов type AppendOp = AppendOp with static member Append(AppendOp, xs1, xs2) = Array.append xs1 xs2 static member Append(AppendOp, xs1, xs2) = List.append xs1 xs2 let inline append (xs1: 'a) (xs2: 'a) : 'a = let inline delayedAppendResolution (t: ^t) (a: ^a) (b: ^a) : ^r = ((^t or ^r): (static member Append: ^t -> ^a -> ^a -> ^r) (t, a, b)) delayedAppendResolution AppendOp xs1 xs2 append [ 1..3 ] [ 27..30 ] |> printfn "%A" append [| 1..3 |] [| 27..30 |] |> printfn "%A"
https://t.me/fsharp_chat/273924 :))
Обсуждают сегодня