-
-
Save dtchepak/11080115 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//Experiment, based on http://withouttheloop.com/articles/2014-04-18-fsharp-csharp-statemachines/ | |
open System | |
type Particulars = { buyer: string; seller: string } | |
type Draft = private Draft of Particulars | |
type Approved = private Approved of (Particulars * DateTime) | |
type Historical = private Historical of (Particulars * DateTime) | |
let createDraft = Draft | |
let approve timestamp (Draft p) = Approved (p, timestamp) | |
let retire timestamp (Approved (p,_)) = Historical (p, timestamp) | |
// usage | |
let contract = createDraft { buyer = "Acme"; seller = "Initech" } | |
let approved = approve DateTime.Now contract | |
let retired = retire DateTime.Now approved | |
retired |> printfn "%+A" | |
type Contract = Choice<Draft, Approved, Historical> | |
//let invalid = approve DateTime.Now approved |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment