4 ms·
>String concatenation actually does associate; Oh my goodness, my brain exploded apparently because I meant to say commute, although commutation is usually not
by clusmore 10y ago
>String concatenation actually does associate;
Oh my goodness, my brain exploded apparently because I meant to say commute, although commutation is usually not something to be expected of monoids.
>Using Num rather than Monoid probably has better ergonomics, and may be closer to intent anyway.
You're probably right on this point, in all honesty. I think I'm over-generalising the original intent.
>With a domain-relevant name, we'd have a sense of what ways it makes sense to restrict the types
Yes, I think this is the classic helper function vs library function quandary. If you wrote it to help yourself right now, it's often good to be very specific with the name and signature. That way if later you need to add more functionality you can without changing the name or restricting the signature. If you wrote it as a library function, it's good to be generic, to let as many people use it as possible. And in this case there should never be a need to change the function, it does what it does. If you need something else you just create something else.
- dllthomas 10y agoThis resonates with some things I've found myself saying recently around misunderstandings of the DRY principle. It's so catchy an acronym, and so seemingly self-explanatory, a lot of people don't realize it was originally framed in terms of knowledge, not syntax. So if syntax happens to be the same in N places, but in each of those places it is the way it is for a different reason, consolidating may not be "DRYing up the code". On the other hand, if I need to say "there's a text field here" in my markup and also in my logic, that could be more DRY even though the syntax looks nothing alike. Tying this back here, we find as a corollary: when factoring out code we can ask ourselves "what piece of knowledge does this represent?" If it is knowledge about the language (this is a good way to sort things) it probably goes in a library, and should probably be very general. If it is knowledge about your domain (this is how we escape HTML), it probably goes in a domain-specific library, and it should probably be somewhat less general. If it is knowledge about your application, it probably goes in your application or an application-specific library, and should probably be pretty specific.