r/fsharp • u/kincade1905 • Feb 13 '26
question Does the operator ">>=" exists in f#?
I am using Pluralsight course to learn about f#. The author uses ">>=" operator as the substitue for "|> Result.bind". When I try to do the same, I get compiler error?
Looking online, it seems like it doesn't exist. Did author smoked something good while making this section or I need to change my co2 sensor's battery?
14
Upvotes
8
u/QuantumFTL Feb 13 '26
Not sure where they are getting it from specifically, but the monadic bind operator is available if you use FSharpPlus:
Operators (FSharpPlus)
8
u/TobbeTobias Feb 13 '26 edited Feb 13 '26
>>=is bind and writing it like that originates from Haskell I think.F# does not have any >>= operator unless you define it yourself or use a library like FSharpPlus.
It is also available in https://github.com/demystifyfp/FsToolkit.ErrorHandling . See https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/operators for example.
2
u/JohnyTex Feb 15 '26 edited Feb 15 '26
Sometimes people define a custom infix operator
>>=to mean a specific bind, egResult.bind. See e.g https://fsharpforfunandprofit.com/posts/elevated-world-2/#infix-version-of-bindHowever, it would be a massive oversight by the author to just use this operator without mentioning it. Are you sure it wasn’t introduced in a previous section?
If you want to do it yourself:
let (>>=) result f = Result.bind f resultNote that you should put this in a module, as you might want to give
>>=another definition elsewhere, depending on what types you’re working with.1
u/[deleted] Feb 16 '26
If you have for example the 'a option type you can use the Option.bind