Extend is Cosemigroupad
- Dominant language
- Haskell
- Stars
- 76
- Forks
- 46
- PR merge metrics
- No merged PRs in 30d
Description
I've discovered that there's such a thing as a `Cosemigroupad` which doesn't have extract and some of its instances are also zippy applicatives. I think this is your `Extend` typeclass. It is a superclass of `Comonad`.
Also there's a more interesting typeclass `Focal` which I suspect doesn't have a dual and which provides parallels to `duplicate` and `extend` where a `Cosemigroupad`'s `duplicate` method gives a related `Comonad` (eg `class (Cosemigroupad w, Comonad w') => Focal w w' where focii :: w a -> w' a`).
I think `Cosemigroupad` should be added with duplicate and extend ready to be the superclass of `Comonad` and then the `Focal` typeclass can be added to a new package.
This `Focal` typeclass also provides demotion from a `Comonad` to it's counterpart `Cosemigroupad` and direct promotion (cf. `duplicate`) along with an instance-specific `HyperMaybe w w'` datatype - which gives zero or more variants of `Nothing` - one for each `Cosemigroupad` value that isn't represented in the `Comonad`. We'll also have `parPromote :: w -> HyperMaybe w'`.
This is a bit like discrete division of types where `HyperMaybe w w'` is the remainder, `Comonad w'` is the divisor and `Cosemigroupad w` is the numerator.
For `Focal List NonEmpty` `HyperMaybe` = `Maybe` and the `parPromote` equals `nonEmpty :: List a -> NonEmpty a`. Every `Comonad w` is a `Cosemigroupad w` where `Focal w w` so we can say `class Cosemigroupad w => Comonad w` and `instance Comonad w => Focal w w` and that for `Focal w w`, `HyperMaybe` = `Identity` and there is therefore a subclass of `Focal` with `totPromote :: w -> w' = id`.
The list instance of `Cosemigroupad` will duplicate to include the empty list - this is important for `Focal [] NonEmpty` so `focii = (:|) <*> ((toList . focii) `uponTail`) where uponTail f as = maybe [] (f . NonEmpty.tail) (NonEmpty.nonEmpty as)` and `duplicate = fromJust . focii` demonstrating the utility of `Focal` for tightly typed programs.
If `Cosemigroupad` can replace `Extend` with the `duplicate` and `extend` names and where `duplicate` provides empty values (for example `duplicate [1,2,3] = [[1,2,3],[2,3],[3],[]]`) then I'll get on with making the package to provide `Focal`.
Furthermore, I think `kfix` can be provided for `Cosemigroupad`s via `class Cosemigroupad w => ZipApply w` although I think it should be `kfix f = fix (fonerstep f)` and `fonerstep f w = f <.> (duplicate w)` because when we split the recursive step away from the fixedpoint combinator we can use enhanced combinators that decorate such as by printing a subseries of the approximations.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading the existing Extend and Comonad definitions and their list instances, then assess the proposed Cosemigroupad, Focal, HyperMaybe, and kfix APIs. The issue names no files or tests; completion would require an agreed scope and documented behavior for the new typeclasses and list operations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 15/100