Skip to content

Instantly share code, notes, and snippets.

@AnthonyMastrean
Last active August 29, 2015 13:57
Show Gist options
  • Save AnthonyMastrean/9356031 to your computer and use it in GitHub Desktop.
Save AnthonyMastrean/9356031 to your computer and use it in GitHub Desktop.
It only multiplies three numbers...
open FSharpx.Option
/// hour, a unit of time
[<Measure>] type h
/// megawatt, a unit of power
[<Measure>] type MW
/// pounds sterling, a unit of currency
[<Measure>] type ``£``
let energy() =
// ... an expensive computation ...
None
let price() =
// ... an expensive computation ...
Some 10.0<``£``/MW/h>
let factor() =
// ... an expensive computation ...
Some 2.0
let revenue (energy: float<MW h>)
(price: float<``£``>)
(factor: float) =
energy * price * factor
maybe {
let! energy = energy() // computation exits here
let! price = price()
let! factor = factor()
return revenue energy price factor
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment