{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreidu3lelmlhd7zc5gjipohnkyh2ztu3fmzzwqhfyntami5d4kxbedq",
"uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3mgoffsqxbjy2"
},
"path": "/t/sneak-peek-bolt-math/13766#post_11",
"publishedAt": "2026-03-10T00:02:20.000Z",
"site": "https://discourse.haskell.org",
"tags": [
"pie-in-the-sky shopping list of algebraic classes",
"`acts`"
],
"textContent": "I also have a pie-in-the-sky shopping list of algebraic classes. I think you have finessed yours in a lot of ways that I haven’t, but there might be things in there that you can borrow.\n\nSome thoughts about your design:\n\n * I would strongly encourage you to name the classes to match existing Haskell patterns, to minimise the disruption to existing practitioners, and to prevent newcomers from getting stuck in your own little custom universe. This heuristic leads me to suggest `FromInteger` over `ExpressibleByIntegerLiteral`, for example. I’d also be careful how you name the `ConvertibleTo` classes because unlike the `ExpressibleBy`/`From` classes, you don’t actually have a source file containing a literal that’s being parsed, and e.g. both `Integer` and `Rational` can generate values with arbitrarily large textual representations.\n * I’d extend this heuristic to using the real mathematical names for things, which I think is fine if you give them really good haddocks and thorough motivations and examples. Package `acts` is a good example of this, but we can go even further. Although I wasn’t there when it was defined, I consider the historical weirdness of `Num` a result of not shopping from the algebraic catalogue.\n * I can see why you’d want to put each arithmetic operation into its own class, but if you’re going to do that I’d consider putting the traditional operators in there.\n * I have baked in the assumption that my operations are all closed, whereas you have chosen to define associated type families for the result types. I recommend checking whether type inference is still good enough in your design. Not being able to reason from the type of a result of basic algebraic operation back through to the argument types could force a lot of manual type signatures in intermediate `let`s in complex numeric code, ballooning contexts in your type signatures, or other syntactic noise.\n * I think you’ve done a lot more thinking about where the miscellaneous numeric functions need to go, which I’ve glossed over in my post. Good.\n * Both of our sketches have a real issue with law-only typeclasses. They’re dangerous for inference (your code infers a signature that doesn’t include a class whose law you rely on) and AFAIK nobody has a thorough solution yet.\n * With these large class hierarchies, there’s also a real problem asking people to implement/derive the entire hierarchy for their types. Again, I don’t think anyone’s got a full answer yet, especially when one wants to add a new class to the middle of the hierarchy.\n * You might need equivalents to `stimes` and `mtimes` which can do repeated squaring for efficiency.\n\n",
"title": "Sneak Peek: Bolt Math"
}