Last active
August 29, 2015 13:57
-
-
Save AnthonyMastrean/9356031 to your computer and use it in GitHub Desktop.
It only multiplies three numbers...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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