TextualMonoid has plenty of functionality that would be useful for non-Char containers, so I was thinking about ways to generalize it.
It seems like the core concept is that for a subset of FactorialMonoid's, the primes can fit a more restricted type than the original type, and can always be injected back into the original type with singleton. It seems like a decent abstraction is then to encode this directly:
class FactorialMonoid m => ContainerMonoid m where
type Element m :: Type
uncons :: m -> Maybe (Element m, m)
singleton :: Element m -> m
And then the laws are basically that it is completely compatible with FactorialMonoid when you use uncons and singleton to roundtrip back and forth between element and container types.
Also on a side note it seems like it would be useful to tie FactorialMonoid into the existing Reductive* hierarchy somehow, particularly since it directly exposes splitPrimePrefix which seems like it should be related to stripPrefix in the form:
stripPrimePrefix c == Just (a, b) ==> stripPrefix a c == Just b
I'm still not 100% sure how this would ideally mesh with the regular Foldable/Functor hierarchy and things like Mono*, but I think the above should still be a nice thing to have and an improvement on focusing specifically on Char.
TextualMonoidhas plenty of functionality that would be useful for non-Charcontainers, so I was thinking about ways to generalize it.It seems like the core concept is that for a subset of
FactorialMonoid's, the primes can fit a more restricted type than the original type, and can always be injected back into the original type withsingleton. It seems like a decent abstraction is then to encode this directly:And then the laws are basically that it is completely compatible with
FactorialMonoidwhen you useunconsandsingletonto roundtrip back and forth between element and container types.Also on a side note it seems like it would be useful to tie
FactorialMonoidinto the existingReductive*hierarchy somehow, particularly since it directly exposessplitPrimePrefixwhich seems like it should be related tostripPrefixin the form:I'm still not 100% sure how this would ideally mesh with the regular
Foldable/Functorhierarchy and things likeMono*, but I think the above should still be a nice thing to have and an improvement on focusing specifically onChar.