Git Product home page Git Product logo

Comments (3)

kailuowang avatar kailuowang commented on June 18, 2024

Definitely interesting to me. I also remember seeing mentioning of interest in this.
A PR would be great!

from cats-tagless.

LukaJCB avatar LukaJCB commented on June 18, 2024

I'm not sure I fully understand ReifiedInvocation but Invocation can be seen as a specialization of Program :) see here: https://github.com/typelevel/cats-tagless/blob/master/core/src/main/scala/cats/tagless/optimize/Program.scala

from cats-tagless.

notxcain avatar notxcain commented on June 18, 2024

@LukaJCB Program is fine as a replacement for Invocation if there is a constraint that exists for all F[_], e.g. some Unconstrained[F[_]]
Another example for ReifiedInvocations is this:

def router[K, F[_]: Concurrent, M[_[_]]: ReifiedInvocations: FunctorK](load: K => F[M[F]): F[K => M[F]] =
  MVar[F].of(Map.empty[K, M[F]]).map { instancesVar =>
    { key: K =>
      ReifiedInvocations[M].invocations.mapK {
        new (Invocation[M, ?] ~> F) {
          override def apply[A](invocation: Invocation[M, A]): F[A] =
            for {
              instances <- instancesVar.take
              mf <- instances.get(key) match {
                     case Some(mf) => instancesVar.put(instances) >> mf.pure[F]
                     case None =>
                       load(key).flatMap { mf =>
                         instancesVar.put(instances.updated(key, mf)).as(mf)
                       }
                   }
              a <- invocation.invoke(mf)
            } yield a
        }
      }
    }
  }

So it allows you to transform some M[_[_]] instance, even if you don't have it yet.
In other words ReifiedInvocations#invocations makes it possible to create an instance that does nothing other than captures method invocations, which you can run later against some other instance.

from cats-tagless.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.