F#: Formatting Discriminated Unions with Tuples

Let’s reformat the following types:

type Account =        
    | Checking of decimal
    | Savings  of decimal
    | Business of decimal

type Command =
    | Withdraw of Account * decimal
    | Deposit  of Account * decimal
    | Transfer of Account * Account * decimal

type Response =
    | Withdrawal       of State   * State
    | WithdrawalFailed of Account * decimal

    | Deposited        of State   * State             
    | DepositFailed    of Account * decimal

    | Transferred      of TransferSummary   * decimal
    | TransferFailed   of Account * Account * decimal

and State =
    | BeforeDeposit    of Account * decimal
    | AfterDeposit     of Account

    | BeforeWithdrawal of Account * decimal
    | AfterWithdrawal  of Account

and TransferSummary = { 
    FromBalanceBefore: Account ; ToBalanceBefore: Account
    FromBalanceAfter:  Account ; ToBalanceAfter:  Account }

To:

type Account =        
    | Checking of decimal
    | Savings  of decimal
    | Business of decimal

type Command =
    | Withdraw of Account * balance: decimal
    | Deposit  of Account * balance: decimal
    | Transfer of from:     Account * 
                  dest:     Account * 
                  balance:  decimal
type Response =
    | Withdrawal       of before: State * 
                          after:  State

    | WithdrawalFailed of Account * balance: decimal

    | Deposited        of before: State * 
                          after:  State     
                                 
    | DepositFailed    of Account * balance: decimal

    | Transferred      of TransferSummary   * balance: decimal
    | TransferFailed   of from:    Account * 
                          dest:    Account * 
                          balance: decimal
and State =
    | BeforeDeposit    of Account * balance: decimal
    | AfterDeposit     of Account

    | BeforeWithdrawal of Account * balance: decimal
    | AfterWithdrawal  of Account

and TransferSummary = { 
    FromBalanceBefore: Account ; ToBalanceBefore: Account
    FromBalanceAfter:  Account ; ToBalanceAfter:  Account }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s