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

Add mapK to Tracer, SpanBuilder, etc. #284

Merged
merged 2 commits into from
Oct 3, 2023

Conversation

NthPortal
Copy link
Contributor

@NthPortal NthPortal commented Jul 24, 2023

Add mapK to Tracer, Tracer.Meta, SpanBuilder, SpanOps, Span, Span.Backend, and InstrumentMeta.

Add KindTransformer type used by mapK implementation, allowing for a single mapK implementation that supports many transformation target types (OptionT, EitherT, IorT, StateT, Kliesli, Resource) with very little work needed to add additional or custom ones.

see #261 for previous work, and #264 for a less complex but less powerful alternative

  • scaladocs
  • rebase -i --autosquash

@NthPortal NthPortal mentioned this pull request Jul 24, 2023
@NthPortal
Copy link
Contributor Author

NthPortal commented Jul 26, 2023

I managed to write up a PoC implementation of KindTransformer that defines G in terms of F. however, it turns out that the added flexibility of being able to theoretically mapK over F ~> H is undermined by the inability to summon the needed context bounds of an arbitrary H (e.g. Functor). additionally, such a definition makes it difficult or impossible to use KindTransformer for types of G that are defined only indirectly in terms of F (whether via type aliases, type members or implicit transformations), thus making the PoC implementation less versatile. so it is going to the code graveyard.

but for posterity...
trait KindTransformer[F[_], G[_[_], _]] {
  type GoF[x] = G[F, x]

  val liftK: F ~> GoF

  def mapK[H[_], A](ga: GoF[A])(f: F ~> H): G[H, A]

  final def liftFunctionK[H[_]](f: F ~> H): GoF ~> G[H, *] =
    new GoF ~> G[H, *] {
      def apply[A](ga: GoF[A]): G[H, A] = mapK(ga)(f)
    }
}

@NthPortal
Copy link
Contributor Author

rebased to fix conflict; autosquashed while I was at it

@NthPortal
Copy link
Contributor Author

what's needed to move this PR forward? cc @iRevive @rossabaker

@armanbilge armanbilge added this to the 0.3 milestone Sep 1, 2023
Add `mapK` to `Tracer`, `Tracer.Meta`, `SpanBuilder`, `SpanOps`,
`Span`, `Span.Backend`, and `InstrumentMeta`.

Add `KindTransformer` type used by `mapK` implementation, allowing
for a single `mapK` implementation that supports many
transformation target types (`OptionT`, `EitherT`, `IorT`, `StateT`,
`Kliesli`, `Resource`) with very little work needed to add
additional or custom ones.
* higher-kinded type `G`.
*/
@annotation.implicitNotFound("No transformer defined from ${F} to ${G}")
trait KindTransformer[F[_], G[_]] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Which laws KindTransformer should obey? Perhaps we can use Discipline to run law tests? https://typelevel.org/cats/typeclasses/lawtesting.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know and that sounds like a great idea!

Copy link
Member

Choose a reason for hiding this comment

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

I talked to @NthPortal today and we agreed laws are a good idea but shouldn't block progress.

I'll also search through the archives of my brain and try to think of Haskell precedent for similar, but this is good for now.

@iRevive
Copy link
Contributor

iRevive commented Sep 28, 2023

@NthPortal apologies for making you wait for so long. The changes look good to me.
I have a few questions, but we can merge without addressing them.

@iRevive
Copy link
Contributor

iRevive commented Sep 28, 2023

@rossabaker @armanbilge what's your opinion on these changes?

* higher-kinded type `G`.
*/
@annotation.implicitNotFound("No transformer defined from ${F} to ${G}")
trait KindTransformer[F[_], G[_]] {
Copy link
Member

Choose a reason for hiding this comment

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

I talked to @NthPortal today and we agreed laws are a good idea but shouldn't block progress.

I'll also search through the archives of my brain and try to think of Haskell precedent for similar, but this is good for now.

@iRevive iRevive merged commit b1efaa4 into typelevel:main Oct 3, 2023
9 checks passed
@NthPortal NthPortal deleted the Tracer-mapK/PR branch October 4, 2023 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants