Elektrine lite

← Feed

@zwarich@hachyderm.io

Post #3721908

2026-07-10 00:40 UTC

@joe@f.duriansoftware.com @slava@mathstodon.xyz I know we talked about this as part of a shitpost thread, but can either of you think of a good way to combine traits (i.e. type classes) and bytewise equality / hashing while still preserving as much parametricity as possible? The natural thing is to have some marker trait with C++ style specialization, but that destroys a lot of the properties that you would want. @joe@f.duriansoftware.com mentioned (jokingly but maybe not) to just make it required and see how far you get. You could do something where you somewhat extend the meaning of bytewise comparability to recurse to slices (e.g. for contents of dynamic arrays) while excluding some fields at the end (e.g. for capacity fields of dynamic arrays, although perhaps you could just handle this by a coercion from a dynamic array to a slice?). I don't see a great way to get extensional hash sets, though.

Replies (1)

  • @joe@f.duriansoftware.com 2026-07-10 16:55

    @zwarich@hachyderm.io @slava@mathstodon.xyz taking inspiration from D's postblit copy constructors, i wonder if you could boil down bytewise equality/comparison/hashing extensions to a "post-memcmp" operation that provides a hook for those sorts of types to perform additional operations after the bytewise operation doesn't fail or maybe the one trait you implement is an operation that gives you spans to all of the byte ranges that you want compared/hashed

    Open ##3721906