Interpreting the `Reader` trait in "Simplicitly"

84 views Asked by At

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

There are 0 answers