What have you found for these years?

2011-10-13

Is proper variance compatible with objects/classes?

updated 2011-10-14 00:03
Oh wait, so true! See what Martin Odersky said.
So actually it's a natural consequence of covariant lists.
If we really want that kind of type safety in elem method,
then actually we're looking for invariant lists instead.

Then it's a non-issue at all, if we have both kind of lists.

* * *

Is proper variance compatible with objects/classes?

閱讀這篇時,發覺自己已經忘記之前在 Scala 裡讀到的 variance 細節...
趕緊複習一下這篇:
1658. 05-02 scala type system (1) covariance and contravariance
不過這篇倒是不用複習,我印象還很深:
1655. 05-02 scala type system (0) unit, top, bottom, and null

然後大概就可以理解他的意思了..

簡單地說就是,應該沒有理想解吧。像 Scala 這樣說不定就是最好的狀況了。
但是說真的,這寫起來就很彆扭,總讓我有種還不如去用 Haskell 算了的感覺。
從完全相反的角度來看的話,那又何苦把事情搞得這麼複雜,像 Java 那樣
大家都 Object 然後不斷 type cast 然後 catch exception 不就得了?
C++ template 那又是另一回事....

再想想我一直沒完全搞懂的 ML module

再瞧瞧一直還沒細看 Josh 的 Modularising Inductive Families

模組化真的是個很難搞的東西... 偏偏寫大程式又一定要模組化。
還是說實際上,我們需要一個可以改變的模組系統,可在程式規模
小的時候使用很簡單的模組系統,而在規模變大時也同時增強模組系統?

0 retries:

Post a Comment

All texts are licensed under CC Attribution 3.0