Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
bblfish
@bblfish:matrix.org
[m]
7 or so years ago I implemented a web server that way. With case classes for PUT, GET, PATCH etc, which could then be turned into Free Monads very much as described on the cats free monad page except that well the interpreters would be actors, and possibly different actors for each command in the free monad stack.
bblfish
@bblfish:matrix.org
[m]
This time I started with simple HttpRequests and HttpResponses, in order to stick to the underlying streaming framework of akka... That works well for the web server.
But for the access control side, it looks I need to either sending code to the data to check for something, or a way to collect a bunch of data, by following appropriate links.
bblfish
@bblfish:matrix.org
[m]
I think it works something like this: one gets a graph of data at a URL, then follows links inside the graph that may give one a URL, that can lead to another graph, etc... But it is quite open ended and dependent on the data. So I guess this is something like a Fold.
Is there a Free Monad type of fold?
bblfish
@bblfish:matrix.org
[m]

I am asking here as it has been quite a few years that I have not looked at these constructs :-)
When I look at the examples on the Cats Free Monad page such as

def program: KVStore[Option[Int]] =
  for {
    _ <- put("wild-cats", 2)
    _ <- update[Int]("wild-cats", (_ + 12))
    _ <- put("tame-cats", 5)
    n <- get[Int]("wild-cats")
    _ <- delete("tame-cats")
  } yield n

this looks like an imperative program with a fixed number of steps essentially. I was thinking of fold, because in my use case the data (a graph) could end up dictating the number of steps one goes through. Think of following links through web pages here.

Rob Norris
@tpolecat
It sounds like you want an effectful unfold.
5 replies
Where you can see local data but can fetch more as you walk the structure.
My Scala World talk does this with a tree structure represented in the database, where it loads data as you walk around. It's a good application of Cofree.
So you might have a look at that.
bblfish
@bblfish:matrix.org
[m]
Ah, interesting that we come into the co-world here :-) Is it this talk Pure Functional Database Programming with Fixpoint Types?
Rob Norris
@tpolecat
yep
bblfish
@bblfish:matrix.org
[m]
You mention the talk by DeGoes at the same conf Streams for (co)Free .
It turns out that just around the time these talks were given was when I started studying coalgebras, coinduction, etc...
Rob Norris
@tpolecat
Oh sorry that was the wrong link. The version I did at Scala World was better.
bblfish
@bblfish:matrix.org
[m]
This one Pure Functional Database Programming‚ without JDBC Scala World, July 11, 2019?
bblfish
@bblfish:matrix.org
[m]
bblfish
@bblfish:matrix.org
[m]
It looks like Matryoshka which you mention in those talks has not moved since 2019 or so. Has it moved elsehwere?
Bob Glamm
@glamm
ok guys, call me crazy, but this should work, right?
def add[F[_]: Monad](ma: F[Int], mb: F[Int]): F[Int] = for { a <- ma; b <- mb } yield a + b
I'm getting value flatMap is not a member of type parameter F[Int], which I think is a sign of .. bad imports, maybe?
yup, I missed cats.implicits._. Darn, disregard
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]