Skip to content

Instantly share code, notes, and snippets.

@t0yv0
Created March 17, 2014 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t0yv0/9604929 to your computer and use it in GitHub Desktop.
Save t0yv0/9604929 to your computer and use it in GitHub Desktop.
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