Overview
Provides Ord instances for common .NET types: DateTime, TimeSpan, DateOnly, TimeOnly, Guid, and Version.
(import (std prelude))
(import (std clr-ord))
;; An alias with a constructor. The Ord instance applies because it
;; refers to the underlying .NET type.
(import/class
(Date (: System.DateTime (-> int int int Date))))
(list-sort (list (Date. 2021 1 1) (Date. 2019 6 5))) ; 2019 first
(less? (Date. 2019 1 1) (Date. 2020 1 1)) ; #t
Import this module to sort and compare these .NET types using
compare, less?, list-sort, and ordered collections.
Each Ord implementation delegates to the type’s CompareTo
method. Equality is handled by default Eq, which delegates to
Equals.
Supported types include System.DateTime,
System.DateTimeOffset, System.TimeSpan,
System.DateOnly, System.TimeOnly, System.Guid, and
System.Version.
Exported aliases. Only Guid and Version are exported
as named aliases to avoid collisions with (std datetime). To use the
other .NET time types, reference their full names (such as
System.DateTime) or declare a local alias via import/class.
The Ord implementations apply to the underlying .NET type regardless
of alias. The exported aliases do not provide constructors; define a local
alias with a constructor if you need to instantiate values directly.
Ordering follows .NET semantics: DateTime compares ticks and ignores
Kind, while DateTimeOffset compares timestamps in UTC.