Repository F# setup
open Reified
open Reified.Refinements
open Reified.Result
open Reified.Schema.JsonSchema Integration
Schema describes structured input: fields, wire representations, path-aware failures, accumulation, and reconstruction. A refinement supplies the value-level step that turns an already-decoded underlying value into an invariant-carrying domain value. Schema can apply that refinement at a field boundary and report its failures at the field's path.
Reified.Refinements has no Schema dependency. Domain types can define refinements without choosing a wire format; an
application that uses Reified.Schema decides where those refinements participate in structured decoding and encoding.
If Schema is new to you, start with the Schema quickstart for fields, record construction, and path-aware diagnostics. Then read Refined Values in Schema for canonical field schemas, raw-value constraints, explicit refinement, and schema-local restrictions. This page is the shorter API-oriented view of that integration.
Refine a primitive schema
open Reified.Refinements
open Reified
let nameSchema : Schema<NonBlankString> =
Schema.text
|> Schema.refine NonBlankString.refinement
ReifiedRefinementsnameSchema: Schema<NonBlankString>Reified.Schema`1Describes a typed value's portable structure and construction for schema interpreters. A schema records shape and construction metadata without tying that metadata to input parsing, diagnostics, validation, codecs, UI generation, or workflow execution. Primitive, collection, optional, union, refined, and record declarations all produce Schema<'value>. Record declarations use the schema<'value> { } computation expression. Each field may contain withSchema, constrain, constraints, refine, and validate operations before the declaration finishes with construct or constructResult.
Reified.Refinements.NonBlankStringA string that is not null, empty, or whitespace.
Reified.SchemaConstruction, composition, parsing, and checking for universal schemas.
text: Schema<string>Describes text input.
(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
refine: Refinement<'raw,'value> -> Schema<'raw> -> Schema<'value>Maps a raw schema through a reusable bidirectional refinement. The smart constructor runs during parsing. Inspection supplies the raw representation during checking and encoding.
Reified.Refinements.NonBlankStringModuleOperations over text known to carry non-whitespace content.
refinement: Refinement<string,NonBlankString>Parsing checks the underlying string, constructs NonBlankString, and reports failures at the schema path. Encoding
and checking project through NonBlankString.Value.
A numeric range is a constraint rather than a refined type, so it goes on the primitive:
field _.Quantity { constrain (Constraint.greaterThan 0) }Schema.constrain is available for a standalone value schema too, but inside a field block
the schema is inferred from the field's type and each constraint sits on its own line.
For an application type:
let emailSchema : Schema<ContactEmail> =
Schema.text
|> Schema.refine ContactEmail.refinementA field block receives the refinement explicitly:
let signupSchema =
schema<Signup> {
field _.Email {
withSchema Schema.text
refine ContactEmail.refinement
}
field _.Age
construct Signup.create
}Choose the operation by meaning
Schema.refine refinement schemaconstructs an invariant-carrying destination and retains refinement metadata.Schema.convert forward backward schemaperforms a total projected mapping.Schema.tryConvert forward backward schemaperforms a fallible projected mapping returningSchemaError list.Schema.admit create project draftSchemaconstructs a domain model from a structured draft while preserving fields.
let centsSchema : Schema<decimal> =
Schema.int
|> Schema.convert decimal int
centsSchema: Schema<decimal>Reified.Schema`1Describes a typed value's portable structure and construction for schema interpreters. A schema records shape and construction metadata without tying that metadata to input parsing, diagnostics, validation, codecs, UI generation, or workflow execution. Primitive, collection, optional, union, refined, and record declarations all produce Schema<'value>. Record declarations use the schema<'value> { } computation expression. Each field may contain withSchema, constrain, constraints, refine, and validate operations before the declaration finishes with construct or constructResult.
decimalAn abbreviation for the CLI type . Basic Types
Reified.SchemaConstruction, composition, parsing, and checking for universal schemas.
int: Schema<int>Describes a 32-bit integer.
(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
convert: ('a -> 'b) -> ('b -> 'a) -> Schema<'a> -> Schema<'b>Maps a schema through a total, reversible domain conversion.
decimal: ^T -> decimalConverts the argument to System.Decimal using a direct conversion for all primitive numeric types. For strings, the input is converted using UInt64.Parse() with InvariantCulture settings. Otherwise the operation requires an appropriate static conversion method on the input type. The input value. The converted decimal. decimal "42.23" // evaluates to 42.23M decimal 0xff // evaluates to 255M decimal -10 // evaluates to -10M
int: ^T -> intConverts the argument to signed 32-bit integer. This is a direct conversion for all primitive numeric types. For strings, the input is converted using Int32.Parse() with InvariantCulture settings. Otherwise the operation requires an appropriate static conversion method on the input type. The input value. The converted int int 'A' // evaluates to 65 int 0xff // evaluates to 255 int -10 // evaluates to -10
let bookingSchema : Schema<Booking> =
bookingDraftSchema
|> Schema.admit Booking.create Booking.toDraftFor the complete progression from a raw field schema to a canonical refined field, continue to Refined Values in Schema.