我想給一個元組作爲printf
功能:餵食元組到功能等printfn
let tuple = ("Hello", "world")
do printfn "%s %s" tuple
這當然不行,編譯器首先說,它需要string
,而不是string*string
。我把它寫成如下:
let tuple = ("Hello", "world")
do printfn "%s %s" <| fst tuple
然後編譯合理注意到,現在我有string -> unit
類型的函數值。說得通。我可以寫
let tuple = ("Hello", "world")
do printfn "%s %s" <| fst tuple <| snd tuple
它適用於我。但我想知道,如果有可能是沒有辦法做到這一點更好,就像
let tuple = ("Hello", "world")
do printfn "%s %s" <| magic tuple
我的問題是,我不能讓這類型不printf的需要,因此印製兩個參數。 magic
功能可能是什麼樣子?
哇!感謝你,我現在明白了!我的'magic'應該看起來像 – Rustam
'let magic op tuple = op <| fst元組<| snd元組' – Rustam
和印刷會像'magic(printfn「%s%s」)元組' – Rustam