Last active
November 1, 2017 21:01
-
-
Save jwood803/6091c0ef9d85503a9d27 to your computer and use it in GitHub Desktop.
Code examples for F# in the Enterprise blog post.
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
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 |
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
[<Measure>] type dollar | |
[<Measure>] type euro |
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
let hasBalance (balance: float option) = | |
match balance with | |
| Some b -> printfn "Balance - %f" b | |
| None -> printfn "No balance available" |
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
type Person = { Name: string } | |
type Employee = { Person: Person; IsActive: bool } | |
let employee = { Person = { Name = "John" }; IsActive = true } |
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
let employee2 = {Person = null; IsActive = false } |
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
open Microsoft.FSharp.Data.UnitSystems.SI.UnitSymbols | |
let meter = 1<m> |
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
// 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment