RefinementModule
PackageReified.Refinements
Creates and applies reusable refinement definitions.
Summary
| Name | Signature | Synopsis |
|---|---|---|
| define | Refinement.define constraint' construct project | Defines a refinement from one constraint, a constructor, and the reverse projection. |
| create | Refinement.create refinement underlying | Constructs a refined value, reporting why the raw value was not admitted. |
| underlying | Refinement.underlying refinement value | Returns the canonical underlying representation of a refined value. |
| constraint' | Refinement.constraint' refinement | Returns the constraint the refinement admits by. |
Defines a refinement from one constraint, a constructor, and the reverse projection.
Parameters
| Name | Type | Description |
|---|---|---|
| constraint' | Constraint<'underlying> | |
| construct | 'underlying -> 'refined | |
| project | 'refined -> 'underlying |
Returns
Refinement<'underlying, 'refined>
Verification Examples
type RetryCount = RetryCount of int
let retryCount =
Refinement.define (Constraint.between 0 10) RetryCount (fun (RetryCount value) -> value)Constructs a refined value, reporting why the raw value was not admitted.
Parameters
| Name | Type | Description |
|---|---|---|
| refinement | Refinement<'underlying, 'refined> | |
| underlying | 'underlying |
Returns
Result<'refined, Violation>
Verification Examples
type RetryCount = RetryCount of int
let retryCount = Refinement.define (Constraint.between 0 10) RetryCount (fun (RetryCount value) -> value)
3 |> Refinement.create retryCount |> Result.mapError Violation.renderReturns the canonical underlying representation of a refined value.
Parameters
| Name | Type | Description |
|---|---|---|
| refinement | Refinement<'underlying, 'refined> | |
| value | 'refined |
Returns
'underlying
Verification Examples
type RetryCount = RetryCount of int
let retryCount = Refinement.define (Constraint.between 0 10) RetryCount (fun (RetryCount value) -> value)
RetryCount 3 |> Refinement.underlying retryCount // 3Returns the constraint the refinement admits by.
Parameters
| Name | Type | Description |
|---|---|---|
| refinement | Refinement<'underlying, 'refined> |
Returns
Constraint<'underlying>
Verification Examples
type RetryCount = RetryCount of int
let retryCount = Refinement.define (Constraint.between 0 10) RetryCount (fun (RetryCount value) -> value)
retryCount |> Refinement.constraint' |> Constraint.inspect