https://github.com/fsprojects/FSharpPlus/blob/4a0b892c62a0ac73d9a13d45b100f6861143f433/src/FSharpPlus/Indexable.fs#L15
type Item =
inherit Default1
static member inline Item (x: '``Indexable<'T>`` , k , []_impl: Default1) = (^``Indexable<'T>`` : (member get_Item : _ -> 'T) x, k) : 'T
static member inline Item (_: 'T when 'T: null and 'T: struct, _, _impl: Default1) = ()
static member Item (x: string , n , []_impl: Item ) = x.[n]
static member Item (x: StringBuilder , n , []_impl: Item ) = x.ToString().[n]
static member Item (x: 'T [] , n , []_impl: Item ) = x.[n] : 'T
static member Item (x: 'T [,] , (i,j) , []_impl: Item ) = x.[i,j] : 'T
static member Item (x: 'T [,,] , (i,j,k) , []_impl: Item ) = x.[i,j,k] : 'T
static member Item (x: 'T [,,,] , (i,j,k,l), []_impl: Item ) = x.[i,j,k,l] : 'T
static member inline Invoke (n: 'K) (source: '``Indexed<'T>``) : 'T =
let inline call_2 (a: ^a, b: ^b, n) = ((^a or ^b) : (static member Item: _*_*_ -> _) b, n, a)
let inline call (a: 'a, b: 'b, n) = call_2 (a, b, n)
call (Unchecked.defaultof, source, n)
타입에 static method로 구현을 만들고
inline 덕타이핑으로 알맞는 구현에 바인딩함
사용은 편한데 코드가 더럽고 쓰레기값도 생김
type Item =
inherit Default1
static member inline Item (x: '``Indexable<'T>`` , k , []_impl: Default1) = (^``Indexable<'T>`` : (member get_Item : _ -> 'T) x, k) : 'T
static member inline Item (_: 'T when 'T: null and 'T: struct, _, _impl: Default1) = ()
static member Item (x: string , n , []_impl: Item ) = x.[n]
static member Item (x: StringBuilder , n , []_impl: Item ) = x.ToString().[n]
static member Item (x: 'T [] , n , []_impl: Item ) = x.[n] : 'T
static member Item (x: 'T [,] , (i,j) , []_impl: Item ) = x.[i,j] : 'T
static member Item (x: 'T [,,] , (i,j,k) , []_impl: Item ) = x.[i,j,k] : 'T
static member Item (x: 'T [,,,] , (i,j,k,l), []_impl: Item ) = x.[i,j,k,l] : 'T
static member inline Invoke (n: 'K) (source: '``Indexed<'T>``) : 'T =
let inline call_2 (a: ^a, b: ^b, n) = ((^a or ^b) : (static member Item: _*_*_ -> _) b, n, a)
let inline call (a: 'a, b: 'b, n) = call_2 (a, b, n)
call (Unchecked.defaultof, source, n)
타입에 static method로 구현을 만들고
inline 덕타이핑으로 알맞는 구현에 바인딩함
사용은 편한데 코드가 더럽고 쓰레기값도 생김
이런 깔-끔한 문법도 있지만
마소쉐키들이 코어 라이브러리 전용으로 달아둬서 딴데선 못씀
|>