-
Notifications
You must be signed in to change notification settings - Fork 703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Density comonad #2029
Density comonad #2029
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
sealed abstract class DensityInstances1 { | ||
|
||
/** Density is a Functor for free */ | ||
implicit def functorInstance[F[_]]: Functor[Density[F, ?]] = new DensityFunctor[F]{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
functorInstance
and cobindInstance
unnecessary because same restriction as comonadInstance
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed: c37a7fb
@stephen-lazaro I have noticed you have done some great job at implementing Density (https://github.com/stephen-lazaro/persians/blob/master/src/main/scala/sl/persians/Density.scala). In particular you got further in implementing Apply and Applicative instances and some nice work around Cofree. Do you want to contribute to this PR? |
@lemastero Sure! I would be happy to. Thanks for thinking of me! |
merge origin
} | ||
|
||
/** Density is a free Comonad */ | ||
private trait DensityComonad[F[_]] extends Comonad[Density[F, ?]] with DensityCobind[F] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just define all methods in DensityComonad
and remove DensityCobind
and DensityFunctor
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DensityCobind and DensityFunctor removed: 4e3d574
@stephen-lazaro It seems Density Comonad is interesting concept yet has not much application. |
@lemastero I've proposed |
The symmetry is useful for learning. I'm happy to add the instances regardless, as I think they are interesting. |
Density Comonad based on Haskell implementation: kan-extensions/Control.Comonad.Density
Density complete the duality matrix of kan extensions:
| Yoneda | Codensity | Kan |
| Coyoneda | Density | Lan |
It is simpler version of Left Kan Extension. It is also Comonad for free like Day, CoFree.
It is already implemented in Purescript and Haskell:
Some methods in Haskell Control.Monad.Co use it: diter dctrlM
It was studied on blogs:
People play around with it:
I have turned the relationship between Density and Lan as laws:
lanToDensity(d.densityToLan) == d
lanToDensity(l).densityToLan == l
Probably it would be nice to add, as a law, relationship between density and Cobind:
d.lowerDensity andThen liftDensity = d
I think it is worth to add, so people might play around with it. WDYT?