{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreibc2ljzlazeuc66s4guqulja4pumy5zi5ehi3fszajq5gjr2ctvse",
"uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3mhljn67plqq2"
},
"path": "/t/sneak-peek-bolt-math/13766?page=2#post_33",
"publishedAt": "2026-03-21T16:07:46.000Z",
"site": "https://discourse.haskell.org",
"textContent": "ashokkimmel:\n\n> I was just thinking that for `Function 0 '[]`, it’s not really a function.\n\nIt’s a value - a function with no arguments that returns itself!\n\nL0neGamer:\n\n> I like the concepts here, but I’m struggling with the feeling that we could do slightly better by combating the boolean-ness with parse don’t validate.\n\nIt has always bothered me that these typeclasses were solely attached to the type eg `Int` when the proper convention is unambiguously defined as the combination of an operator and a type eg `(+, Int)`.\n\nBut in all seriousness, Parse Dont Validate is a design pattern, and this is a mathematical description, so they are orthogonal but complementary. How do you know when to return `Nothing` instead of `Just` when parsing? The design pattern doesn’t omit checks, it performs them up front and uses types to propagate their legality - and these classes provide the laws that could be used during the parse.\n\nL0neGamer:\n\n> It feels odd for me that with all this talk of checking for lawfulness there’s no “proof” carried through to let you do the operation, or even that lawful doesn’t just do the operation for you.\n\n_Perhaps I need to add a`Legal` data family that connects a Lawful instance to a data type’s wrapper that expresses that it satisfies the law and does exactly this. I also feel like there is some interaction to be had with the `WellDefined` class…_\n\nRemember, these new classes don’t displace newtypes for distinguishing between _validly different types_ eg like Natural and Whole numbers which are distinguished by the presence or lack of a zero `0` - we need those to combat boolean blindness, as you said. Newtype of this kind are thus still quite useful, and so I would expect to eg wrap up a value in such a newtype to propagate that law, once I have proven (witnessed?) that it obeys.\n\nWhat the new classes do is replace the newtypes that get used as a shim to allow a single type to conform to and temporarily access multiple instances of the same typeclass - ie using `Sum` and `Product` to select between `Addition` and `Multiplication` during a fold so you can take advantage of `Monoid`. Newtypes of this kind are more of a hack. There is some nuance and overlap between the two use cases, so many newtypes get used in both ways.\n\n* * *\n\nI’m still shaking out this design quite heavily - as pleased as I am with the result, it is only _my first successful attempt_ at expressing this rigor, and there are a few things I don’t like about it, so I’m not afraid to make changes - keep the feedback coming.",
"title": "Sneak Peek: Bolt Math"
}