Repository F# setup
open Reified
open Reified.Refinements
open Reified.Result

Constraints

Maturity: Incubating

Reified.Constraint describes which typed values are acceptable. A constraint can be checked directly, reused by a refined type, attached to a Schema field, inspected for documentation, and rendered in another language.

dotnet add package Reified.Constraint
Verified
open Reified
open Reified.ConstraintDSL

let username = Constraint.all [ present; minLength 3; maxLength 30 ]

Constraint.check username "ada"
// Ok ()

Constraint.check username ""
// Error (All (Atomic (Expected (PresenceAtom Present, None)),
//             [ Atomic (Expected (CardinalityAtom (Cardinality.Minimum 3),
//                                Some (ConstraintValue.Integer 0L))) ]))
Requires & types
Requires: open Reified; open Reified.ConstraintDSL (packages: Reified.Constraint)
val username: Constraint<string>

Constraints return the standard F# Result<unit, Violation>. They do not depend on Reified.Result; use that package, FsToolkit.ErrorHandling, or ordinary pattern matching when you need to compose the result with other work.

Start here

Use Parsing when serialized text must first become a typed value. Use Refined when successful admission should be recorded in the type. Use Schema when fields of a structured input need paths and accumulated diagnostics.