Skip to content
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

Merged
merged 9 commits into from
Feb 9, 2019
Merged

Density comonad #2029

merged 9 commits into from
Feb 9, 2019

Conversation

lemastero
Copy link
Contributor

@lemastero lemastero commented Nov 17, 2018

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?

Copy link
Contributor

@emilypi emilypi left a 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]{}
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: c37a7fb

@xuwei-k xuwei-k added the scalaz7 Scalaz 7.x label Nov 18, 2018
@lemastero
Copy link
Contributor Author

@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?

@stephen-lazaro
Copy link

@lemastero Sure! I would be happy to. Thanks for thinking of me!

}

/** Density is a free Comonad */
private trait DensityComonad[F[_]] extends Comonad[Density[F, ?]] with DensityCobind[F] {
Copy link
Member

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.

Copy link
Contributor Author

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

@lemastero lemastero changed the title [WIP] Density comonad Density comonad Nov 20, 2018
@lemastero
Copy link
Contributor Author

@lemastero Sure! I would be happy to. Thanks for thinking of me!

@stephen-lazaro It seems Density Comonad is interesting concept yet has not much application.
If you want, you can create PR with Apply/Applicative instances for Density, but chances are, that it will not end up in Scalaz :(

@emilypi
Copy link
Contributor

emilypi commented Dec 3, 2018

@lemastero I've proposed Density before for sz8 and sz7 (and implemented Codensity for the former), however, I was met with the same utilitarian arguments. Personally, I think that if it is a useful abstraction for study, or completeness, then it should be written, however, I also understand that this produces noise and slower compile times for users. Chances are other people will disagree, and it's certainly a valid argument going the other way. I hope it goes in though.

@stephen-lazaro
Copy link

stephen-lazaro commented Dec 3, 2018

The symmetry is useful for learning. I'm happy to add the instances regardless, as I think they are interesting.

@emilypi emilypi merged commit e5e4f31 into scalaz:series/7.3.x Feb 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scalaz7 Scalaz 7.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy