scala-subscript / subscript

9 stars 2 forks source link

Dataflow operators should stack #4

Closed anatoliykmetyuk closed 8 years ago

anatoliykmetyuk commented 9 years ago

So far, expressions like a ~~(x: T)~~> b ~~(y: T)~~> c are not possible. Parsing fails at second dataflow.

anatoliykmetyuk commented 8 years ago

Should a ~~> b ~~> c be a ~~> [b ~~> c] or [a ~~> b] ~~> c?

AndreVanDelft commented 8 years ago

[a ~~> b] ~~> c is most natural; see 10 - 1 - 2. A special case is when the last arrow is an exception flow. What would we expect of: a ~~> b ~/~> c IMO indeed the left-association would be convenient.

anatoliykmetyuk commented 8 years ago

What's 10-1-2? Just thought about it: rhs associativity grants the best visibility for the leftmost operator. Use case:

             {!getCurrentUser!} ~~(currentUser: String)~~> [
               [repositories.score.last: currentUser ~~(Some((right: Double, left: Double, _)))~~> (new Test(currentUser, right, left, 5))
                                                    +~~(None                                  )~~> (new Test(currentUser, 20   , 20  , 5))]
               ~~((right: Double, left: Double))~~> [
                 repositories.score.write: currentUser, (right, left)
                 (new Result(right, left))
               ]
             ]

Three dataflows here, all right-associative, so that currentUser from the first dataflow can be used even in the last dataflow.

a ~~> b ~/~> c will be parsed as one dataflow, c belongs to a's failure, because the longest match is parsed.

Edit: Second dataflow of the example is left associative though.

AndreVanDelft commented 8 years ago

10 - 1 - 2 = 7, not 11.

anatoliykmetyuk commented 8 years ago

Dataflow is a special case IMO.

scala> classOf[Int => Int => Int]
res0: Class[Int => (Int => Int)] = interface scala.Function1
AndreVanDelft commented 8 years ago

Yes, I am convinced now that right-associativity is the best choice. The use case is great. I recall that about a half year ago I had the same visibility argument in mind, but I forgot it.