A Default Identity Value for Programming (michaelfeathers.silvrback.com) 2 points by farginay 12y ago ↗ HN
[–] npryce 12y ago ↗ J has a similar feature: when applied to an empty array, /+ returns 0 and /* returns 1.J doesn't have user-defined types. In a language with user-defined types, you would probably have to declare which operations are monoids.
[–] dvberkel 12y ago ↗ I would concur with npryce. I your structure would adhere to the monoid interface and the default value could be cast automatically to the corresponding identity this will work. It wouldn't even break mathematics
2 comments
[ 1.9 ms ] story [ 13.3 ms ] threadJ doesn't have user-defined types. In a language with user-defined types, you would probably have to declare which operations are monoids.