Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Adam Rosien
@arosien
yep, or cats.syntax.all._ is the newer way
Rob Norris
@tpolecat
@bblfish:matrix.org yeah the new one is called droste
som-snytt
@som-snytt
Is cats-parse pronounced cats-paws or only in New England?
Rob Norris
@tpolecat
cats paahs, it's wicked fast
tpolecat @tpolecat throws beer bottle
bblfish
@bblfish:matrix.org
[m]
cats-paws would be a good name :-)
Swoorup Joshi
@Swoorup
how do i use this http library
bblfish
@bblfish:matrix.org
[m]
working my way carefully through @tpolecat's talks on Fix points.
it is very intriuging because on the Semantic Web we have a notion that looks similar to the IdProf(id: Int, value: ProfF[IdProf]). Well we have PointedGraphs(node,Graph), which allows one to move through a graph, by following links. But there is also a larger concept of NamedGraph(name: URL, g: Graph) where a graph g is found at the URL name, so that works a bit like the id field in a Database.
bblfish
@bblfish:matrix.org
[m]
case class ProfF[A](name: String, year: Int, students: List[A]) is a functor, and the idea is that the Free structures should be recursive ones I think.
There was a very nice blog post by Runar in 2016 A comonad of Graph Decompositions. Sadly it seems to have been his last blog post.
And the Quiver library they were working on has been archived. I wonder if the work there has been followed up anywhere else.
Rob Norris
@tpolecat
Free structures aren’t necessarily recursive. Option is the free pointed set for instance.
bblfish
@bblfish:matrix.org
[m]
Last time I was looking in the direction of Free and CoFree I found this paper Free for DSLs, cofree for interpreters. Does that fit your experience there @tpolecat ?
bblfish
@bblfish:matrix.org
[m]
It does not really look like you were using CoFree as an interpreter in your examples.
Rob Norris
@tpolecat
I haven’t read that paper but Dave Laing knows what he’s taking about.
Alexander Van Hecke
@alexandervanhecke
is there a way to go from F[A => F[B]] to F[A => B] given a Monad[F]?
1 reply
Fabio Labella
@SystemFw
not in that shape, no. What's the larger problem?
Alexander Van Hecke
@alexandervanhecke
I have an F which is a MonadState and I need to implement a function that returns an F[List[Byte] => List[String]]. The returned function should take the bytes, store them in the state and return some value (here a List[String]). I got as far as an F[List[Byte] => F[List[String]]], but need a way to flatten out the second F effect
Fabio Labella
@SystemFw

need to have something that returns an F[List[Byte] => List[String]]

that's the wrong type for your operation

you need List[Byte] => F[List[String]]
the type F[List[Byte] => List[String]] does not let you do the operation that you want
(this is related to the difference between Applicative and Monad btw)
Alexander Van Hecke
@alexandervanhecke
ah excellent suggestion ... let me see if I can make that work. thanks!
Fabio Labella
@SystemFw
let me know if you want to know why that type is incorrect
Alexander Van Hecke
@alexandervanhecke
yes, I'm all ears
Fabio Labella
@SystemFw
so, one of the intuitions for purely functional effects (which is incorrect), is that you have functions that return results and additionally do some effects which appear in the type
instead, you have functions which returns programs, which in turn represent the execution of some effects
e.g def foo(s: String): IO[Int] is not a function that takes a String, returns an Int, and does some IO
it's a function that takes a String and returns an IO[Int] program, which in turn represents the eventual production of an Int + some effects
the other concept is that A => B means that B depends on A
so, in your case, State[Something, List[Byte] => List[String]] represents a program which return a functions List[Byte] => List[String]
but because you want to store the bytes in the state
there has to be a dependency between the thing that can express "input" (list of bytes) and the thing that can express "put in the state", i.e. the F
so you have to have A => F[Something]
if you do F[A => B] there is no way for the state do depend on A (literally the shape does not allow it)
Alexander Van Hecke
@alexandervanhecke
indeed you are right ... thanks for writing that down for me
Fabio Labella
@SystemFw
eventually it's going to be become evident when you are asking for an impossible type :)
another way to look at it is that if you could take an A => F[B] and make it into an F[A => B], you could take any Monad and express it via Applicative instead, and therefore Monad would have no reason to exist
given:
map: (A => B) => F[A] => F[B]
ap  :  F[A  => B] => F[A] => F[B]
flatMap:  (A => F[B)) => F[A] => F[B]
monad is adding that "dependence"
Alexander Van Hecke
@alexandervanhecke
:+1: I wasn't thinking straight ... being Monday morning and all :)
Oleg Pyzhcov
@oleg-py
For intuition, I find it helpful to "read" the types left-to-right, threating [...] as parentheses
val readFileContents: String => IO[Array[Byte]] // given a string, do some IO, return array of bytes.
// vs
val readFileContents_?: IO[String => Array[Byte]] // do some IO, return a function, that when given a string will, without any more IO, give bytes out.
bblfish
@bblfish:matrix.org
[m]
It helps to understand the duality between algebras and coalgebras.
(Free) Algebras give you a Program that does effects such as IO.
Coalgebras are what execute that program, by a sequence of state changes.
bblfish
@bblfish:matrix.org
[m]
:point_up: Edit: It helps to understand the duality between algebras and coalgebras.
(Free) Algebras give you a Program that does or rather describes effects such as IO.
Coalgebras are what execute that program, by a sequence of state changes.
:point_up: Edit: It helps to understand the duality between algebras and coalgebras.
(Free) Algebras give you a Program that does or rather describes effects such as IO.
Coalgebras are machines that execute such programs, by a sequence of state changes.
(At least that is what the CoFree Papers I mentioned above seem to be pointing to -- the coalgebra as machine si pretty well established)
bblfish
@bblfish:matrix.org
[m]
There is one interesting feature of Free is that it is easy to put together a DSL and try out if it gives one what is needed by building out a really simple interpreter (based on hashmaps say). So I'll try that :-)
Greg Fisher
@gnfisher
I'm getting into some trouble with implicits, cats, and doobie... I am unsure how to start to approach this:
 both value AsyncConnectionIO in object connection of type => cats.effect.Async[doobie.free.connection.ConnectionIO]
 and method catsFreeMonadForFree in class FreeInstances of type [S[_]]=> cats.Monad[[β$21$]cats.free.Free[S,β$21$]]
 match expected type cats.Functor[[x]doobie.ConnectionIO[x]]
  def reportMissingPart: Pipe[
    ConnectionIO,
    PriceBookEntry.Salesforce,
    PriceBookEntry.Salesforce
  ] = _.chunks.evalTap { chunk =>
  ...
}
is the function I'm getting the error on.
Oleg Pyzhcov
@oleg-py
@gnfisher using scala 3 by any chance?
oh probably not. You can try doing import doobie.free.connection.AsyncConnectionIO as a temporary fix before anybody with actual doobie experience can help :D