Scala ではトレイトの相互再帰的合成ができるけれども、それを実際のプロジェクトで使わないのと同じような理由で、 cake pattern による DI も、(まともに機能すると信じて)実際のプロジェクトに使うことはない気がする
-
Show this thread
-
Replying to @m2ym
The cake pattern works so much better with dynamically typed language with lazy evaluation such as Nix or Jsonnet. In Scala, inheritance of lazy fields is incorrect, the cake is more verbose, and restricted to compile-time specialization.
1 reply 0 retweets 0 likes -
Replying to @Ngnghm
Is there "trait composition" in Nix or Jsonnet? I couldn't find that by quick search. Carefully defined lazy fields should work in any dynamic language, IMO, but that's not a point, I think.
1 reply 0 retweets 0 likes -
Replying to @m2ym
All inheritance is "trait composition" in Nix or Jsonnet. And there is a correct way to inherit lazy fields that preserves the sharing of computation nodes where bad ways fail badly, causing exponential duplication of state and other effects (ouch).
1 reply 0 retweets 0 likes -
Replying to @Ngnghm
If a computation graph is acyclic, a computation node (or thunk) of the graph will be evaluated at most once and can be trivially shared. I think it is not a problem even in Scala (except for the initialization order problem, of course), right?
1 reply 0 retweets 0 likes -
Replying to @m2ym
Once again, Scala doesn't implement inheritance of lazy fields. If you "simply" inherit a nullary function definition instead, you get exponential effect duplication and lack of proper state sharing as children inherit.
1 reply 0 retweets 0 likes -
Replying to @Ngnghm
Stumble upon this issue. So what you mean by "incorrect" is that overriding lazy vals with super self-reference goes wrong?https://github.com/lampepfl/dotty/issues/1999 …
1 reply 0 retweets 1 like -
Replying to @m2ym
My understanding is that in Scala, you're not allowed to reference the inherited value of the lazy val from the super class.
1 reply 0 retweets 0 likes -
Replying to @Ngnghm
I think this problem is essentially caused by a name collision. In Jsonnet, there seems to be two namespaces: self and super. Actually "jsonnet -e '{ a: 1, b: 2 } { a: super.b, b: 3, c: self.b }'" says "{ a: 2, b: 3, c: 3 }",
1 reply 0 retweets 0 likes -
(cont) which cannot be constructed if there is just one namespace (or cell).
2 replies 0 retweets 0 likes
Which is why my proposal for how to implement that in Scala involved one cell per override / one namespace per superclass.
-
-
Replying to @Ngnghm
Fully understand. Great proposal. I have never been aware of that problem.
1 reply 0 retweets 1 like -
- 3 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
Read my blog!