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

Refactor of Context instance hierarchy #383

Merged
merged 1 commit into from
Sep 23, 2020
Merged

Refactor of Context instance hierarchy #383

merged 1 commit into from
Sep 23, 2020

Conversation

Odomontois
Copy link
Member

No description provided.

trait ContextInstances[TC[f[_], r] >: WithContext[f, r]] extends LocalInstances[TC]

/** lightweight version of ApplicativeLocal
* consider to use `WithLocal` or `In` for better type inference
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* consider to use `WithLocal` or `In` for better type inference
* consider using `WithLocal` or `In` for better type inference

BTW, type In[C, F[_]] = WithContext[F, C] doesn't seem to be a proper alternative for Local, does it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, an artifact of hasty copypasta

type HasContext[F[_], C] = Context[F] { type Ctx = C }

type HasLocal[F[_], C] = Local[F] { type Ctx = C }

type HasProvide[F[_], G[_], C] = Provide[F] { type Ctx = C; type Lower[A] = G[A] }

type HasContextRun[F[_], G[_], C] = RunContext[F] { type Ctx = C; type Lower[A] = G[A] }
type HasContextRun[F[_], G[_], C] = RunContext[F] { type Lower[A] = G[A]; type Ctx = C; }
Copy link
Member

Choose a reason for hiding this comment

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

Does this swap affect inference anyhow? Why hasn't HasProvide been changed?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this change is insignificant. Just a scar of searching how to make ReaderT instance work inside ContextBase companion

@@ -3,13 +3,15 @@ import cats.{ApplicativeError, MonadError}
import cats.data.Ior

package object tofu {
type In[C, F[_]] = WithContext[F, C]
Copy link
Member

Choose a reason for hiding this comment

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

What's the use?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just small type alias to write X In F instead of F WithContext X

def apply[F[_]](implicit ctx: RunContext[F]): HasContextRun[F, ctx.Lower, ctx.Ctx] = ctx
type Aux[F[_], G[_], C] = HasContextRun[F, G, C]

final implicit def readerTContext[F[_]: Applicative, C]: HasContextRun[ReaderT[F, C, *], F, C] =
Copy link
Member

Choose a reason for hiding this comment

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

So we still can't avoid this even with Kai's approach?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, unfortunately, scala reject to search parent companions for Aux-types with lifted higher-kinded type-members.
So, removing this and Provide's one makes ContextSuite fail

}

/** a mix-in for supplying environment data type companions with useful things */
trait Companion[C] {
Copy link
Member

Choose a reason for hiding this comment

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

Usage examples?

Copy link
Member Author

@Odomontois Odomontois Sep 19, 2020

Choose a reason for hiding this comment

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

  • usage examples

@Odomontois Odomontois merged commit fb0d6b0 into master Sep 23, 2020
@Odomontois Odomontois added enhancement New feature or request and removed enhancement New feature or request labels Sep 23, 2020
@catostrophe catostrophe added the enhancement New feature or request label Oct 7, 2020
@Odomontois Odomontois deleted the context branch March 3, 2021 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants