typelevel / cats

Lightweight, modular, and extensible library for functional programming.
https://typelevel.org/cats/
Other
5.25k stars 1.21k forks source link

Add environment comonad #1729

Open andyscott opened 7 years ago

andyscott commented 7 years ago

Would a PR to add EnvT (https://hackage.haskell.org/package/comonad-5.0.1/docs/Control-Comonad-Trans-Env.html) be a reasonable addition?

One implementation, in Scala, appears in Matryoshka: https://github.com/slamdata/matryoshka/blob/master/core/shared/src/main/scala/matryoshka/patterns/EnvT.scala

adelbertc commented 7 years ago

Hm given Matryoshka is planning on moving to Cats (ping @sellout ) do we want this in Cats, and is this "generally useful" enough to be in something like cats-core?

edmundnoble commented 7 years ago

We already have this, without its own datatype, in instances.tuple. My questions are: do we want it as its own type like Reader? Do we want the transformer? And what will we do with comonad transformers in general?

sellout commented 7 years ago

Yeah, I dunno – Haskell does alias Env to EnvT Id, but I would generally just use tuples. In Matryoshka we use EnvT two ways – for its structure as the pattern functor of Cofree and then in gzygo, which actually uses it as a transformer. I suppose that given some MTL-style type class, I would use that instead, which hadn’t even occurred to me until now.

But I have no problem keeping it all in Matryoshka until/if it’s useful for someone else, or if someone wants to build the dual of cats-mtl or whatever. But if it’s in Cats, I’ll definitely get rid of my definition of it.