frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

Show HN: Galois connections for composable numeric casts in Rust

https://github.com/cmk/connections
7•partialsolve•1h ago

Comments

partialsolve•1h ago
Hi HN — I just published 0.1.0 of `connections`, a Rust port of an older Haskell library I wrote.

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.

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:

    ceil(a) <= b  iff  a <= upper(b)
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.

A small example of the boundary behavior:

    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);
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:

    lower(b) <= a  iff  b <= floor(a)
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.

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.

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.

This isn’t intended to replace `TryFrom`: validation, runtime-parameterized conversions, and caller-selected policies generally belong in ordinary named functions.

Install:

    cargo add connections
Docs: https://cmk.github.io/connections/ Examples: https://github.com/cmk/connections/blob/main/EXAMPLES.md Crate: https://crates.io/crates/connections

I'd appreciate any feedback you can give me. Cheers!

Kimi K3 is now live

https://www.kimi.com/en
509•vincent_s•3h ago•257 comments

Microsoft Comic Chat is now open source

https://opensource.microsoft.com/blog/2026/07/16/microsoft-comic-chat-is-now-open-source/
203•jervant•2h ago•55 comments

Decoy Font

https://www.mixfont.com/experiments/decoy-font
113•ray__•2h ago•40 comments

Detecting LLM-Generated Texts with “Classical” Machine Learning

https://blog.lyc8503.net/en/post/llm-classifier/
58•uneven9434•1h ago•23 comments

NotebookLM is now Gemini Notebook

https://blog.google/innovation-and-ai/products/gemini-notebook/notebooklm-gemini-notebook/
63•xnx•2h ago•40 comments

OnePlus halts operations in USA and Europe

https://community.oneplus.com/thread/2170715118587871237
428•pilililo2•8h ago•241 comments

Goes-19 weather satellite enters Safe Hold mode

https://www.spaceweather.gov/news/goes-19-safe-hold
106•yabones•5h ago•52 comments

The lost joy of music piracy

https://www.pigeonsandplanes.com/read/music-piracy-what-cd-oink-nine-inch-nails-streaming
678•mcgin•13h ago•453 comments

Adaptional (YC S25) Is Hiring

https://www.ycombinator.com/companies/adaptional/jobs
1•acesohc•1h ago

How Our Rust-to-Zig Rewrite Is Going

https://rtfeldman.com/rust-to-zig
252•jorangreef•6h ago•133 comments

Immersive Linear Algebra Book with Interactive Figures

https://immersivemath.com/ila/
44•srean•2h ago•4 comments

Launch HN: Traceforce (YC S26) – Company-wide security monitoring for AI apps

12•XiaHua•1h ago•6 comments

Someone Used AI to Write an Unauthorized Biography of Me

https://www.nytimes.com/2026/07/16/technology/ai-slop-books-biography-amazon.html
25•igonvalue•1h ago•34 comments

How to Train a Gen AI Kick Drum Model on Your Old Linux Desktop with 6GB VRAM

https://www.zhinit.dev/blog/training-a-kick-drum-diffusion-model
39•zhinit•3h ago•27 comments

Guide to data tools landscape for developers

https://sinja.io/blog/data-landscape-guide-for-developers
53•OlegWock•3h ago•12 comments

Sony deletes more movies from the accounts of people who ‘bought’ them

https://www.techdirt.com/2026/07/15/sony-deletes-a-bunch-more-movies-from-the-accounts-of-people-...
399•nekusar•6h ago•238 comments

Let's Build PlanetScale from Scratch: Infrastructure

https://onatm.dev/2026/07/16/homescale-part-1/
108•onatm•6h ago•16 comments

Ente – Opening Our Books

https://ente.com/open/
170•Sherex•7h ago•64 comments

Show HN: Leaves – A text-UI disk usage treemap visualizer

https://github.com/patonw/leaves
22•patonw•2h ago•6 comments

GC shape stenciling in Go generics

https://rednafi.com/go/gc-shape-stenciling/
33•ingve•4d ago•5 comments

Cottage Computer Programming (1984)

https://www.atariarchives.org/deli/cottage_computer_programming.php
11•lioeters•4d ago•2 comments

Show HN: A modern port of Linux to a ten-year-old QWERTY phone

19•tmzt•2h ago•2 comments

Agent-talk: Enabling coding agents to work together

https://github.com/xhluca/agent-talk
14•xhluca•2h ago•5 comments

SPCX is now Wall Street's most shorted new stock

https://invezz.com/news/2026/07/16/the-worlds-most-valuable-ipo-spcx-is-now-wall-streets-most-sho...
19•lbrito•26m ago•10 comments

56,000 lines of DOOM, in a language I made up

https://betlang.dev/about/
24•ghuntley•2h ago•14 comments

42% of adults rely on their parents for financial support

https://www.cnbc.com/2026/07/16/42percent-of-adults-rely-on-their-parents-for-financial-supportth...
33•root-parent•1h ago•20 comments

Schema Harness Achieves ~99% on Arc‑AGI‑3 Public

https://schema-harness.github.io/
18•jasondavies•3h ago•2 comments

1,300 Beautiful Wildlife Illustrations from the 19th Century Now Restored

https://www.openculture.com/2026/07/explore-1300-beautiful-wildlife-illustrations-from-the-19th-c...
213•gslin•15h ago•40 comments

Teardown: A Generic 7-Port USB 3.0 Hub That Wasn't

https://goughlui.com/2026/07/09/teardown-a-generic-7-port-usb-3-0-hub-that-wasnt/
180•speckx•4d ago•86 comments

Show HN: Galois connections for composable numeric casts in Rust

https://github.com/cmk/connections
7•partialsolve•1h ago•1 comments