// Option 1: binds// Not much different to your solution, but slightly less repetitivelet (+.) xy=Option.bind (funx'->Option.bind (funy'->Some (x'+y')) y) x
(Some10) +. (Some20)
[
Some10Some5Some6
]
|>List.reduce (+.)
// Option 2: With maybe monad from FsharpxopenFSharpx.Optionlet (+..) xy=maybe {
let!x'=xlet!y'=yreturnx'+y'
}
-------------------- type List<'T> = | ( [] ) | ( :: ) of Head: 'T * Tail: 'T list interface IEnumerable interface IEnumerable<'T> member Head : 'T member IsEmpty : bool member Item : index:int -> 'T with get member Length : int member Tail : 'T list static member Cons : head:'T * tail:'T list -> 'T list static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
val reduce : reduction:('T -> 'T -> 'T) -> list:'T list -> 'T
Full name: Microsoft.FSharp.Collections.List.reduce