Created
March 17, 2014 18:08
-
-
Save t0yv0/9604929 to your computer and use it in GitHub Desktop.
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 M = | |
[<PrivateRecordConstructor>] // how about F# had something like this? | |
type Config = | |
{ | |
A: string | |
B: string | |
// ... | |
} | |
let Create () = | |
{ | |
A = "default" | |
B = "default" | |
} | |
module B = | |
let X : M.Config = { A = "A"; B = "B" } // type error | |
let Y = M.Create().B // ok | |
let Z = { M.Create() with A = "A" } // ok | |
// why? because creating records by specifying all fields | |
// outside of the defining module is leads to code that breaks | |
// when the record is extended. it is an anti-pattern, | |
// not currently enforced | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment