Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard option workflow in F#?

Is there an option (maybe) wokflow (monad) in the standrd F# library?

I've found a dozen of hand-made implementations (1, 2) of this workflow, but I don't really want to introduce non-standard and not very trusted code into my project. And all imaginable queries to google and msdn gave me no clue where to find it.

like image 897
CheatEx Avatar asked Oct 19 '11 08:10

CheatEx


1 Answers

There's no standard computation builder for options, but if you don't need things like laziness (as added in the examples you linked) the code is straightforward enough that there's no reason not to trust it (particularly given the suggestively named Option.bind function from the standard library). Here's a fairly minimal example:

type OptionBuilder() =     member x.Bind(v,f) = Option.bind f v     member x.Return v = Some v     member x.ReturnFrom o = o     member x.Zero () = None  let opt = OptionBuilder() 
like image 128
kvb Avatar answered Sep 27 '22 19:09

kvb