Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a practical difference between this two getters, in F#?

Tags:

f#

I'm wondering about the two syntax for the getters:

type Direction =
    | Undefined
    | Buy
    | Sell

    member this.Symbol =
        match this with
        | Direction.Buy       -> '↑'
        | Direction.Sell      -> '↓'
        | Direction.Undefined -> '→'

    member this.Symbol2 with get() =
        match this with
        | Direction.Buy       -> '↑'
        | Direction.Sell      -> '↓'
        | Direction.Undefined -> '→'
    

Is there any practical difference between the first one and the second one? The IL looks identical, but from the usage standpoint? is one preferred for any reason?

like image 795
Thomas Avatar asked Oct 24 '25 02:10

Thomas


1 Answers

They are identical, yes. In general, prefer the first one. The reason why the second one exists is if you have some special logic to do that isn't just grabbing a value. It's more flexible, but more syntax.

like image 89
Phillip Carter Avatar answered Oct 26 '25 18:10

Phillip Carter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!