Std.Refine
View source →Refinement type combinators.
This module pairs common refinement-type aliases with matching
runtime predicates. The aliases are type-level constraints
used in function signatures; the predicates are plain Bool-
returning helpers for use at call sites.
Examples
use Std.Refine
# Signature uses the refinement type alias; the value is an
# ordinary integer satisfying the constraint.
fn decrement(n: Positive) -> NonNegative = n - 1
positive?(3) # => true
percentage?(42) # => true
probability?(0.9) # => true
Types
-
type NonZero (refinement)Non-zero integer (
Intminus zero). -
type Positive (refinement)Strictly positive integer.
-
type Negative (refinement)Strictly negative integer.
-
type NonNegative (refinement)Non-negative integer (zero or positive).
-
type NonPositive (refinement)Non-positive integer (zero or negative).
-
type Percentage (refinement)Integer between 0 and 100 inclusive (a percentage).
-
type PositiveFloat (refinement)Strictly positive float (e.g. probability density, weight).
-
type Probability (refinement)Float in
[0.0, 1.0]inclusive (a probability).
Functions
-
# fn __group__() -> Atom
Group tag consumed by
Cure.Stdlib.Preload. -
# fn non_negative?(n: Int) -> Bool
truewhennis non-negative. -
# fn percentage?(p: Int) -> Bool
truewhenpis a valid percentage (0..100 inclusive). -
# fn positive?(n: Int) -> Bool
truewhennis strictly positive. -
# fn probability?(p: Float) -> Bool
truewhenpis a valid probability (0.0..1.0 inclusive).