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 IdT, the identity monad transformer #588

Merged
merged 2 commits into from
May 26, 2016

Conversation

vikraman
Copy link
Contributor

No description provided.

@vikraman vikraman changed the title Add idT, the identity monad transformer Add IdT, the identity monad transformer Oct 27, 2015
@vikraman
Copy link
Contributor Author

I don't see a MonadTrans yet, should that be added?

@codecov-io
Copy link

Current coverage is 84.00%

Merging #588 into master will decrease coverage by -0.15% as of 15596c2

@@            master   #588   diff @@
=====================================
  Files          162    163     +1
  Stmts         2222   2244    +22
  Branches        74     74       
  Methods          0      0       
=====================================
+ Hit           1870   1885    +15
  Partial          0      0       
- Missed         352    359     +7

Review entire Coverage Diff as of 15596c2

Powered by Codecov. Updated on successful CI builds.

@ceedubs
Copy link
Contributor

ceedubs commented Oct 31, 2015

Thanks, @vikraman!

I've never used IdT before. Do you have an example of how/why one might want to use it?

@xuwei-k
Copy link
Contributor

xuwei-k commented Nov 4, 2015

I think IdT should be an own data type, not type alias.

@non
Copy link
Contributor

non commented Nov 16, 2015

@vikraman What do you think? Would you be willing to make this its own data type as @xuwei-k suggests? I am starting to feel like we should avoid type aliases in cases like these.

@vikraman
Copy link
Contributor Author

Yes, I just ran into diverging implicits with this alias, I'll change it to a proper data type.

@vikraman
Copy link
Contributor Author

Updated.

@aryairani
Copy link
Contributor

Ditto to @ceedubs's question

def map[B](f: A => B)(implicit F: Functor[F]): IdT[F, B] =
IdT(F.map(value)(f))

def flatMap[B](f: A => IdT[F, B])(implicit F: Monad[F]): IdT[F, B] =
Copy link
Contributor

Choose a reason for hiding this comment

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

should be replace the constraint from Monad to FlatMap?

@vikraman
Copy link
Contributor Author

I think it is useful to have IdT since it is the most trivial transformer. It would be useful to have the definitions of liftM once there is a MonadTrans class.

@xuwei-k
Copy link
Contributor

xuwei-k commented Nov 24, 2015

xuwei-k@5b426cc249bd1f46d92b8d2

[error] /home/travis/build/xuwei-k/cats/tests/src/test/scala/cats/tests/IdTTests.scala:10: ambiguous implicit values:
[error]  both method idTFunctor in class IdTInstances of type [F[_]](implicit F: cats.Functor[F])cats.Functor[[β]cats.data.IdT[F,β]]
[error]  and method idTMonad in class IdTInstances of type [F[_]](implicit F: cats.Monad[F])cats.Monad[[β]cats.data.IdT[F,β]]
[error]  match expected type cats.Functor[[β]cats.data.IdT[F,β]]
[error]   def idTFunctor[F[_]: Monad] = implicitly[Functor[IdT[F, ?]]]
[error]                                           ^

@vikraman
Copy link
Contributor Author

Split the instances to avoid ambiguous implicits.

@non
Copy link
Contributor

non commented Jan 4, 2016

Sorry for the long silence.

I'm fine with merging this -- I do think we probably want to write a few more words about how it works (e.g. "If M[_] is a monad, then IdT[M, ?] provides an equivalent monad" or similar) but that can happen in a future PR.

👍

@julien-truffaut
Copy link
Contributor

LGTM 👍

@julien-truffaut julien-truffaut merged commit 236199e into typelevel:master May 26, 2016
@julien-truffaut julien-truffaut mentioned this pull request May 26, 2016
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.

7 participants