2
我可以使用管道運算符的模塊和靜態成員函數的函數。我可以在非靜態成員函數中使用它嗎?具有成員函數的管道運算符
我的類:
type MyClass =
class
new() = {}
member this.isZero(number: int): bool =
number = 0
static member returnInt(): int =
33
end
使用靜態成員:
MyClass.returnInt() |> Console.WriteLine // prints 33
使用非靜態成員:
let foo = new MyClass()
foo.isZero(2) |> Console.WriteLine // prints false
我想使用非靜態函數從我目的。語法無效:
let foo = new MyClass()
foo |> member MyClass.isZero(2) |> Console.WriteLine
我想使用F#的清晰語法。
你想要實現的代碼是「使用非靜態成員「不行? 'member'永遠不會在實際的成員聲明中使用。 – TeaDrivenDev
我認爲OP正在試圖做到這一點:https://fslang.uservoice.com/forums/245727-f-language/suggestions/5663326-syntax-for-turning-properties-into-functions不,不可能,這是不可能的。在你的例子中,做'foo.isZero(2)'有什麼問題? –