2

In "Simplicitly: foundations and applications of implicit function types", Odersky et al. briefly introduce the Reader monad, just to replace it with a superior alternative one paragraph later. This is what the given definition looks like:

trait Reader[R, A] {
  def ask: R
  def local[A](f: R => R)(a: A): A
}

Thinking that I roughly understand the idea behind Reader, I've repeatedly glanced over the definition, without actually reading it. But now, while re-reading this paper, I'm just staring at it, struggling to understand what it's trying to tell me. The [A] after local, as well as the seemingly completely unconstrained A in Reader[R, A] look odd.

Here is what I looked at while trying to figure out what it should have meant:

  • The def local in object Reader in Cats seems perfectly clear: it just precomposes an f: R => R to a Reader[R, A], nothing surprising here.
  • The Ask in Cats-MTL has a superficially similar shape, but it's an MTL-style trait describing the capability of a monad F[_]. In the paper, there is no F[_] in the first place.
  • Similarly for Local: in the Cats-MTL, it's all about the capabilities of the F[_]; Also, there is no additional [A].
  • There is the Haskell MonadReader typeclass, whose ask and local signatures look very similar, but again, it's describing the capabilities of a monad m.

It looks as if the Reader from the paper combined the definitions of MTL Ask and Local, but then removed any mention of the monad that's being described. It's like "MTL", but without the "M" in it - not sure how to interpret it.

  • Is it a typo?
  • If it is one: does my hypothesis about how this typo occurred seem plausible?
  • Are there other closely related definitions that would help make sense of this one?
  • There is a "monad instance omitted"-remark right before the code block. Is there some kind of convention about "omitting" all the M[_]s and F[_]s in "the obvious" positions?
Andrey Tyukin
  • 43,673
  • 4
  • 57
  • 93
  • From what you can read between the lines: Odersky does NOT like monads and he is NOT in favor of expressing effects in your return type. Also he see little benefit in referential transparency. So he seem to prefer to express effects on input side in the form of implicits and (recently) "Capabilities". So I'd expect his `Reader` to be just an implicit which would contain some `R`, which you could extract or mutate. But I have to yet read this paper, so I can be wrong. – Mateusz Kubuszok Jul 24 '22 at 19:03

0 Answers0