5

This is a follow-up to my previous question.

As I understand from Haxl and Stitch they use a monad for data access. The monad is actually a tree of data access commands. The children are the commands the node depends on. The siblings are executed concurrently.

The business logic creates the monad and then a separate function fetch interprets it.

Now, the question: Suppose I am performing a few data access operations concurrently. I can use an applicative functor (not a monad), which is just a list of commands (not a tree).

Does it make sense ? What if the list contains duplicate commands ?

Community
  • 1
  • 1
Michael
  • 41,026
  • 70
  • 193
  • 341

1 Answers1

2

I think by construction of the Fetch values the possibility of repeating the same query is avoided, even in the same round of queries (when they are "siblings" as you say). If you look at the paper, the figure 4 explains the implementation of dataFetch, which is the constructor of Fetch values. It accounts for three possibilities:

  1. The request has never been made before
  2. The request has been made before AND it has been completed
  3. The request has been made before but it has not been completed yet

In the last case you will notice that the value returned has an empty sequence of BlockedRequests, because in this case some other Blocked fetch has it. This way, when the ap function is called with this value it won't concatenate the same repeated request.

BTW I have been trying to implement Haxl in Scala here.

miguel
  • 714
  • 7
  • 17
  • any comparison about your version and `stitch` ? – zinking May 22 '16 at 02:26
  • 1
    @zinking mine's is a very naive and direct translation from Haskell. I think there may be problems with concurrent access to the cache which are not be present in Stitch. If you want a better implementation 47 degrees just published [one](http://www.47deg.com/blog/fetch-scala-library) which I think is also faithful to Haxl and surely must be better than my implementation. There is also [clump](http://getclump.io/). – miguel May 25 '16 at 18:34