<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Hacker News: partialsolve</title><link>https://news.ycombinator.com/user?id=partialsolve</link><description>Hacker News RSS</description><docs>https://hnrss.org/</docs><generator>hnrss v2.1.1</generator><lastBuildDate>Thu, 16 Jul 2026 22:17:07 +0000</lastBuildDate><atom:link href="https://hnrss.org/user?id=partialsolve" rel="self" type="application/rss+xml"></atom:link><item><title><![CDATA[New comment by partialsolve in "Show HN: Galois connections for composable numeric casts in Rust"]]></title><description><![CDATA[
<p>Hi HN — I just published 0.1.0 of `connections`, a Rust port of an older Haskell library I wrote.<p>It's intended to address a common issue with casting: each cast's individual behavior is specified, but the syntax doesn’t describe what a cast and its reverse do together. Once several conversions are chained, their rounding, saturation, and range choices become difficult to reason about compositionally.<p>The core type packages a pair of monotone functions intended to satisfy a Galois law. A left connection, for example, has `ceil: A -> B` and `upper: B -> A`, with:<p><pre><code>    ceil(a) <= b  iff  a <= upper(b)
</code></pre>
There is a right-handed `lower`/`floor` form as well. When one embedding has both adjoints, the crate exposes `round`, `truncate`, interval, and related operations.<p>A small example of the boundary behavior:<p><pre><code>    use connections::conn::ConnR;
    use connections::core::u032::U032I032;

    assert_eq!(u32::MAX as i32, -1);
    assert_eq!(U032I032.floor(u32::MAX), i32::MAX);
    assert_eq!(U032I032.lower(-1), 0_u32);
</code></pre>
Here `as` preserves the low bits and wraps to -1, while this connection saturates. The claim isn’t that saturation is universally better; it is that the choice is explicit and paired with its reverse under:<p><pre><code>    lower(b) <= a  iff  b <= floor(a)
</code></pre>
The main payoff is composition. Provided the components satisfy their laws, Galois connections compose, so the compile-time composition macros preserve the relationship without inventing a new rounding policy at each hop.<p>0.1.0 includes families for Rust integers, IEEE floats, NonZero values, chars, sortable byte encodings, and IP/socket addresses, with optional Q-format, civil-time, hifitime, and hybrid-clock families. The default core has no third-party runtime dependencies; `Conn` is Copy, const-constructible, heap-free, and the crate forbids unsafe code.<p>Every included connection has a proptest law suite. Generated integer, Q-format, NonZero, and isomorphism families also have Kani harnesses over their full bit-width domains. The float claims are deliberately narrower and documented separately; floats use an N5 wrapper so NaN participates in an explicit reflexive preorder rather than being quietly excluded.<p>This isn’t intended to replace `TryFrom`: validation, runtime-parameterized conversions, and caller-selected policies generally belong in ordinary named functions.<p>Install:<p><pre><code>    cargo add connections
</code></pre>
Docs: <a href="https://cmk.github.io/connections/" rel="nofollow">https://cmk.github.io/connections/</a>
Examples: <a href="https://github.com/cmk/connections/blob/main/EXAMPLES.md" rel="nofollow">https://github.com/cmk/connections/blob/main/EXAMPLES.md</a>
Crate: <a href="https://crates.io/crates/connections" rel="nofollow">https://crates.io/crates/connections</a><p>I'd appreciate any feedback you can give me. Cheers!</p>
]]></description><pubDate>Thu, 16 Jul 2026 16:36:52 +0000</pubDate><link>https://news.ycombinator.com/item?id=48936809</link><dc:creator>partialsolve</dc:creator><comments>https://news.ycombinator.com/item?id=48936809</comments><guid isPermaLink="false">https://news.ycombinator.com/item?id=48936809</guid></item><item><title><![CDATA[Show HN: Galois connections for composable numeric casts in Rust]]></title><description><![CDATA[
<p>Article URL: <a href="https://github.com/cmk/connections">https://github.com/cmk/connections</a></p>
<p>Comments URL: <a href="https://news.ycombinator.com/item?id=48936803">https://news.ycombinator.com/item?id=48936803</a></p>
<p>Points: 24</p>
<p># Comments: 2</p>
]]></description><pubDate>Thu, 16 Jul 2026 16:36:17 +0000</pubDate><link>https://github.com/cmk/connections</link><dc:creator>partialsolve</dc:creator><comments>https://news.ycombinator.com/item?id=48936803</comments><guid isPermaLink="false">https://news.ycombinator.com/item?id=48936803</guid></item></channel></rss>