F# makes it easy to define types such as
type coords = { X : float; Y : float }
but how do I define constraints/check arguments for the con
You can make the implementation private. You still get structural equality but you lose direct field access and pattern matching. You can restore that ability using active patterns.
//file1.fs
type Coords =
private {
X: float
Y: float
}
[]
module Coords =
///The ONLY way to create Coords
let create x y =
check x
check y
{X=x; Y=y}
let (|Coords|) {X=x; Y=y} = (x, y)
//file2.fs
open Coords
let coords = create 1.0 1.0
let (Coords(x, y)) = coords
printfn "%f, %f" x y