Skip to content

Generalizing TextualMonoid #25

@tysonzero

Description

@tysonzero

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions