How do you decide between writing a function inside a module or as a static member of some type?
For example, in the source code of F#, there are lots of types that
In addition to the other answers there is one more case to use Modules:
For value types they can help to define static properties that do not get re-evaluated every time they are accessed. for example:
type [] Point =
val x:float
val y:float
new (x,y) = {x=x;y=y}
static member specialPoint1 = // sqrt is computed every time the property is accessed
Point (sqrt 0.5 , sqrt 0.5 )
[]
module Point =
let specialPoint2 = // sqrt is computed only once when the Module is opened
Point (sqrt 0.5 , sqrt 0.5 )