Created
May 25, 2015 11:14
-
-
Save mastoj/059f8cb24a4ae912be6f to your computer and use it in GitHub Desktop.
An answer to http://blog.bjartwolf.com/?p=4522
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
module Person = | |
open System | |
type PersonState = private { id: Guid; name: string; age: int} | |
let createPerson id name age = {id = id; name = name; age = age} | |
let changeName name personState = {personState with name = name} | |
let changeAge age personState = | |
// some crazy business rule involving age | |
{personState with age = age} | |
module SomeOtherModule = | |
open System | |
open Person | |
// let bjorn = { id=System.Guid.NewGuid(); name="Bjørn Einar"; age=34} // won't compile | |
let bjorn = createPerson (Guid.NewGuid()) "Bjørn Einar" 34 | |
let changedBjorn = bjorn |> changeName "Bjørn the less(?) confused" | |
let changedAgedBjorn = changedBjorn |> changeAge 30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If this does what I think it does I will be very happy and indeed less confused.