jwood803
6/21/2014 - 12:13 AM

Code examples for F# in the Enterprise blog post.

Code examples for F# in the Enterprise blog post.

// This will compile
let dollarsToEuros dollars: float<dollar> =
    dollars * 0.74<dollar>

// Won't compile due to a type mismatch
let dollarsToEuroCompileError dollars: float<dollar> =
    dollars * 0.74
open Microsoft.FSharp.Data.UnitSystems.SI.UnitSymbols

let meter = 1<m>
let employee2 = {Person = null; IsActive = false }
type Person = { Name: string }

type Employee = { Person: Person; IsActive: bool }

let employee = { Person = { Name = "John" }; IsActive = true }
let hasBalance (balance: float option) = 
  match balance with
    | Some b -> printfn "Balance - %f" b
    | None -> printfn "No balance available"
[<Measure>] type dollar
[<Measure>] type euro
type BankAccount() =
  member val Balance = Option<float>.None with get, set

  member this.openAccount() =
    this.Balance <- Some 0.0
    this.Balance.Value

  member this.closeAccount() =
    this.Balance <- None

  member this.getBalance() =
    this.Balance.Value