These are chat archives for typelevel/cats

23rd
Apr 2018
Guillaume Bersac
@gbersac
Apr 23 2018 10:33
Hi, I posted this cats related question on stack overflow, please answer it : https://stackoverflow.com/questions/49978898/cats-sequence-error-while-applied-on-list-of-either
Paul Carey
@paulcarey
Apr 23 2018 10:35
Hi, I want to mapN over Validateds I'm creating from Trys. I'm calling leftMap(_.toString) on each Validated, because AFAICT there's no Semigroupal for Throwable. But this seems awkward. Is there a better way?
Fabio Labella
@SystemFw
Apr 23 2018 10:39
@paulcarey you could use a ValidatedNel which is just Validated[NonEmptyList[E], B]
so you still leftMap but putting them in a nonEmptyList
we have several toValidNel, toInvalidNel helpers for that as well
if you don't want to leftMap explicitly
Manuel Cueto
@manuelcueto
Apr 23 2018 10:43
Hey @gbersac I’ve done that before, I might be doing it the wrong way , but what I did was define an applicative for Either (I set the first parameter to throwable and defined a type alias for it). Afterwards you import the implicit ap and type the sequence function when using it
Fabio Labella
@SystemFw
Apr 23 2018 10:44
the problem is that @gbersac does not have partial unification enabled
and that's also why you needed a type alias: you don't need it once you enable the compiler option
Luka Jacobowitz
@LukaJCB
Apr 23 2018 13:08
I’m going to give drafting a complete type class proposal for dotty another shot, would love to hear opinions and feedback once I’ve got more (:
Oleg Pyzhcov
@oleg-py
Apr 23 2018 13:09
@LukaJCB you're doing god's work :+1:
Alex Henning Johannessen
@ahjohannessen
Apr 23 2018 13:41
So I have this yolo[F[_]](implicit F: MonadError[F, Throwable]) and when I try to do something like pr.payload.cast[DurableEvent].toRight(DurableEventRequiredError).liftTo[F] I get could not find implicit value for parameter F: cats.ApplicativeError[F,support.marshalling.akka.PrSerializer.DurableEventRequiredError.type]. This, even when DurableEventRequiredError extends RuntimeException which in turn extends Throwable
Luka Jacobowitz
@LukaJCB
Apr 23 2018 13:42
DurableEventRequiredError.type sounds like it’s using the companion object
Unless you have object DurableEventRequiredError extends RuntimeException
Alex Henning Johannessen
@ahjohannessen
Apr 23 2018 13:44
@LukaJCB case object DurableEventRequiredError extends MarshallingError("Serializer only works with payload of type DurableEvent")
and abstract class MarshallingError(msg: String) extends RuntimeException(msg)
So, I am a bit confused, because MonadError extends ApplicativeError
Luka Jacobowitz
@LukaJCB
Apr 23 2018 13:45
What happens if you do .toRight(DurableEventRequiredError: Throwable) instead?
Alex Henning Johannessen
@ahjohannessen
Apr 23 2018 13:47
@LukaJCB pr.payload.cast[DurableEvent].toRight(DurableEventRequiredError: Throwable).liftTo[F] works
Luka Jacobowitz
@LukaJCB
Apr 23 2018 13:47
Yeah seems like a variance issue
Alex Henning Johannessen
@ahjohannessen
Apr 23 2018 13:47
But can that not be solved in liftTo ?
Luka Jacobowitz
@LukaJCB
Apr 23 2018 13:49
I don’t think so
Alex Henning Johannessen
@ahjohannessen
Apr 23 2018 13:50
Ok, I guess I can live with pr.payload.cast[DurableEvent].toRight[Throwable](DurableEventRequiredError).liftTo[F]
Luka Jacobowitz
@LukaJCB
Apr 23 2018 13:50
You could do maybe do yolo[F[_], E <: Throwable](implicit F: MonadError[F, E])
Alex Henning Johannessen
@ahjohannessen
Apr 23 2018 13:51
I can try experiment with that, thanks for the suggestion :)
Luka Jacobowitz
@LukaJCB
Apr 23 2018 13:51
Subtyping and type classes don’t play along very well I’m afraid :/
Oleg Pyzhcov
@oleg-py
Apr 23 2018 13:54
isn't there .leftWiden or something?
Paul Carey
@paulcarey
Apr 23 2018 14:31
@SystemFw thanks
Apr 23 2018 15:03
there is leftCast[A] and rightCast[A] if you statically know something is a Right or Left, respectively, like in a pattern match
Oleg Pyzhcov
@oleg-py
Apr 23 2018 15:04
I mean in Bifunctor, not concretely for Either
Apr 23 2018 16:28
oh, interesting, there is a leftWiden
i did not know that existed :)
William Turner
@wwwiiilll
Apr 23 2018 17:39
Alright, so I originally posted this on the scala channel, but I guess here is more appropriate, so here I go again:
I have a batch modify use-case here where the user uploads a spreadsheet with the required changes and I'd like to work with an "execution plan" that I'd parse from the file before performing the actual work (I'd optimize, validate, check permissions and similar beforehand). I started pushing towards Free currently because I'm a little familiar with it, but is that the right way to go? How about tagless or recursion schemes?
Piotr Gawryś
@Avasil
Apr 23 2018 17:51
@wwwiiilll I don't feel qualified enough to give proper advice in this matter but this might be useful if you're considering tagless final: https://typelevel.org/blog/2017/12/27/optimizing-final-tagless.html
William Turner
@wwwiiilll
Apr 23 2018 17:56
@Avasil thanks for that, I'll go over it
Apr 23 2018 17:59
@wwwiiilll both Free and finally tagless sound like good use cases of that
id say dont use recursion schemes if this is your first time doing something like this
Free will be a bit easier to introspect if youre going to be doing that a lot
but you can do it with tagless final as well
William Turner
@wwwiiilll
Apr 23 2018 18:08
through discussion in the scala/scala I'm kind of reconsidering this, or at least refocusing it, I might have been overthinking it, thanks a lot for the pointers though
Rob Norris
@tpolecat
Apr 23 2018 20:16
Can anyone point to the theory behind invariant functors?
Alexander Konovalov
@alexknvl
Apr 23 2018 20:24
they are just functors from $C \times C^{op}$ to $C$.
Rob Norris
@tpolecat
Apr 23 2018 20:26
Is that right? The objects aren't pairs.
Alexander Konovalov
@alexknvl
Apr 23 2018 20:26
objects are same as in $C$
but morphisms in $C \times C^{op}$ are pairs of morphisms in both directions from $C$
Rob Norris
@tpolecat
Apr 23 2018 20:27
In a product category the objects are pairs of objects aren't they?
Alexander Konovalov
@alexknvl
Apr 23 2018 20:28
Rob Norris
@tpolecat
Apr 23 2018 20:29
And it's not really Op. The inverted arrow may not exist and may not be unique.
So it seems like it's a functor in the category of types and pairs of functions between types.
Andrey Ivanov
@a-nigredo
Apr 23 2018 20:31
Hi all, are there any examples how to use iterateWhile in Monad?
Alexander Konovalov
@alexknvl
Apr 23 2018 20:32
invariant functors are also known as "exponential functors"
Rob Norris
@tpolecat
Apr 23 2018 20:33
yeah
Usually in cats subtyping indicates a forgetful functor, but not here, at least under any interpretation I can think of.
It bothers me that the relationship seems to be of convenience rather than of some theoretic basis.
So I hope I'm just missing something.
Rob Norris
@tpolecat
Apr 23 2018 20:39
Actually re: op it definitely is wrong because an arrow A → B in Scal_op is a function from B => A in Scal. The arrows represent the same function.
I think. ;-)
Alexander Konovalov
@alexknvl
Apr 23 2018 20:41
I stand corrected, I think you are right.
what are some interesting invariant functors that can not be made into profunctors and aren't IsoFunctors?
Alexander Konovalov
@alexknvl
Apr 23 2018 20:51
For example in Codec[A] we most likely want IsoFunctor
or at least Prism[A, B] => (Codec[A] => Codec[B])
Rob Norris
@tpolecat
Apr 23 2018 21:19
IsoFunctors being functors in the category of groupoids (i.e., where all arrows are ismorphisms)?
That's kind of what got me thinking about invariant … it bugs me that the arrows don't have to be invertible even though they usually are.
Denis Borisenko
@dborisenko
Apr 23 2018 21:34

Hi guys, I couldn't find any natural transformation from Id to IO. I thought, Id can be transformed to any applicative.

implicit def idToApplicative[G[_]](implicit A: Applicative[G]): Id ~> G = new FunctionK[Id, G] {
override def apply[A](fa: A): G[A] = A.pure(fa)
}

Am I violating any law by this code? I couldn't find any law for FunctionK to check

Alexander Konovalov
@alexknvl
Apr 23 2018 21:36
@tpolecat yep
@dborisenko it's totally fine to do that
the natural transformation you are looking for is pure
;)