Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Alexander Konovalov
@alexknvl
case class Free[F[_], A](resume: Either[A, F[Free[F,A]]]) is "data" assuming F is, cats impl is always "co-data".
inductive, co-inductive?
Edmund Noble
@edmundnoble
You could look at it that way, I don't know how useful it is though
Seeing as you have to consume it all to interpret it
Whereas Cofree, you interpret other comonads into
Alexander Konovalov
@alexknvl
That's pretty useful if you want to guarantee termination :)
Although in most cases you don't.
Edmund Noble
@edmundnoble
Yeah that's the canonical issue with Free, all bottoms are the same in some sense
Rob Norris
@tpolecat
I think it's useful to play around with a strict/finite implementation because it's very simple.
The structure is totally obscured in the cats/scalaz impls.
Edmund Noble
@edmundnoble
It's also nice for just growing leafy trees
I appreciate step being constant-time
Jacob Barber
@Jacoby6000
Does cats have an implementation for ForAll? I can't find one
Edmund Noble
@edmundnoble
Nope
Jacob Barber
@Jacoby6000
D:
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]

bad?

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.