Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
Activity
Jacob Barber
@Jacoby6000
Any reason why?
I'll make a PR to add it if not.
Edmund Noble
@edmundnoble
Please do, take that from alexknvl/polymorphic probably
Jacob Barber
@Jacoby6000
:thumbsup:
Jacob Barber
@Jacoby6000
I can not so proudly say I don't understand that implementation at all. lol
Edmund Noble
@edmundnoble
It has no boxing and nice syntax
Alexander Konovalov
@alexknvl
And also the trick with unstable types...
And the trick with final class Foo(val b: Boolean = true) extends AnyVal
Edmund Noble
@edmundnoble
Ugh that trick gives me shame
Alexander Konovalov
@alexknvl
Why? it's quite ingenious.
@Jacoby6000 I think even trait Forall[F[_]] { def apply[A]: F[A] } version is better than nothing.
Doesn't require a separate syntax import
Harrison Houghton
@hrhino
which trick gives you shame?
Jacob Barber
@Jacoby6000
@alexknvl that's what I was leaning toward... But realistically that's so simple that I don't feel like it contributes much.
(unless it can start being applied to already existing parts of the codebase)

Hm... I know implicit conversions are bad, but is

implicit def forallA[F[_], A](forall: ForAll[F]): F[A] = forall.apply[A]

I imagine things would be weird whenever you start composing stuff
Jacob Barber
@Jacoby6000
Applicative should be sufficient, i think.
Also, shouldn't it just be traverseWithIndex not traverseWithIndexM?
Alexander Konovalov
@alexknvl
Curious thing. Given Mu[F] for some F, we can do only [A] (F[A] => A) => A. And AFAIU that should be enough to implement all possible operations on Mu[F]
I have no clue how to implement zip on two Mu[ListF[A, ?]] using only catamorphisms :smile:
Fabio Labella
@SystemFw
re: fs2. It's not quite Free, the algebra is a bit more powerful. Also, most of the API is in final tagless style, so it's not necessarily a good example to see Free in action
Rob Norris
@tpolecat
doobie is free but the interpreter is tagless so it's kind of weird. Also there are 14 algebras with 1000 constructors which presents some design challenges
Andy Scott
@andyscott
@Jacoby6000 the M suffix on traverseWithIndexM indicates that it requires G be a Monad.
I recall a discussion about trying to implement it with Applicative as the constraint… but it wasn’t possible AFAIK. Unless you do it in two passes over the structure F instead of one pass.
Jose Emilio Labra Gayo
@labra

One question, I found that the following code works

    type R1[A] = ValidatedNel[String,A]
val i1 = implicitly[Applicative[R1]]

but the following one doesn't:

    type R2[A] = ValidatedNel[String,(A,A)]
val i2 = implicitly[Applicative[R2]]
Is that right? I am using cats-1.0.0-MF
the error obtained with the second snippet is:
could not find implicit value for parameter e: cats.Applicative[R2]
Fabio Labella
@SystemFw
@labra why do you need an instance of Applicative[R2]? If you have validated of tuples, that you can mapN with a function that takes tuples, the instance you need is ValidatedNel[String, A]
if instead you mapN with a function that operates on A (only operating on the second element of the tuple), you'd need something like Nested
Jose Emilio Labra Gayo
@labra
What surprises me is that if R1 compiles...why does R2 not?
I thought that if there was an applicative instance of ValidatedNel[String,A] then there was also an instance of ValidatedNel[String,(A,A)], but maybe I'm missing something...
Fabio Labella
@SystemFw
it's different. Given that you have an instance for ValidatedNel[String, A] for all A, you can then instantiate the A type variable to any type, including (A, A). But the opposite is not true: if you look for ValidatedNel[String, (A, A)], ValidatedNel[String, A] does not apply.
you don't need ValidatedNel to show this, Option is enough
when you have (('a -> 1).some, ('b -> 2).some)).mapN { case ((x,y), (z,w)) => ???} the compiler looks for Applicative[Option[?]], and after finding it, instantiates the A (as in, there's an instance for Applicative[Option[A]] forall As), to Tuple2[Symbol, Int].
alternatively, you can say you're looking for ValidatedNel[String, (A, ?)], but that's different (and requires Nested)
Fabio Labella
@SystemFw
I can explain it a bit better if you want
Fabio Labella
@SystemFw

it's the difference between:

def foo[A]: Foo[A]
foo[(B,B)]

and:

def foo2[A]: Foo[(A,A)]

where foo is implicit def applicativeForOption[A]: Applicative[Option[A]]

Fabio Labella
@SystemFw

when you do implicitly[Applicative[R1]], you are saying, find me something of type [A] => Applicative[Option[A]] ; once you have this, you can specialise [A] to (B, B). Given the the instance for Option fits the shape [A] => Applicative[Option[A]], it compiles.
When you do implicitly[Applicative[R2]], you are saying, find me something of type [A] => Applicative[Option[(A,A]]. The instance for Option does not have this shape, so it doesn't compile.

* I'm using the fake type [A] => Foo[A] to represent polymorphic methods def foo[A]: Foo[A], Scala does not have first class polymorphic functions

Raphael Mäder
@randm-ch
Hi everyone. I have this code in a unit test:
val m = mock[PageRepository[IO]].smart
m.tearDown returns IO { None }
and I get a codegen.java.lang.Object$MockitoMock$862296327 cannot be cast to cats.effect.IO exception. Does anyone know how to fix this? I'm quite new to cats and I'm unsure how to solve this, especially since the IO class is relatively new and I can't find anything about this issue on google :) thanks!
(the exception is thrown on the second line; stack trace doesn't provide more information)
Harrison Houghton
@hrhino
I'm not very experienced with Mockito, but I think you might be running into an issue with mock only getting the type PageRepository[_]
On account of erasure. Is that a scala mockito wrapper?
Raphael Mäder
@randm-ch
Yes, from the Specs2 library. I'll read about type erasure, maybe I can find something. Thanks for the hint.
Harrison Houghton
@hrhino
Also, what is PageRepository?
If you're writing code that's parameterized over an arbitrary effect type, often you can make testing easier by replacing the effect with a less general one.
Alexandru Nedelcu
@alexandru
Hi folks, I need the Cats logo. Where can I find it?