看板 PLT 關於我們 聯絡資訊
※ 引述《scwg ( )》之銘言: : 在 unify 兩個的時候 class part 取 least upper bound, interfaces 取教交集 : ==> b ? new X() : new Y() has type: A & N1 & N2 : 然後再去 method resolution, 這步沒那麼難, : 一樣把名字和 parameter 數目都對的拿出來, : 每一個 parameter 跟 class & interface1 & interface2 ... : 比較, 可以的留下, 然後再一樣找 most specific method : 在這個例子裡兩個 func 都可以 -- 這個 type 是 A 也有 implement N2 : 但是 A 和 N2 沒有 assignment 關係, 於是可能性不唯一, report error. Mmm... 這樣好像比較了解要怎麼做了, 所以基本上一定還是要找出 unify set, 也就是 { A, N1, N2 }, 然後在搜尋 compatible methods 的階段, 只要 formal paramter type T 跟對應位置的 expression unify set S 有 T.isAssignableFrom( anyOf{S} ) 的關係, 那個 method 就算是 compatible method. 最後再用原本的 algorithm 找出 most specific method, 看看是不是唯一. 這樣對吧? 這樣還是可以在 linear time 找出 compatible methods, 感覺又變簡單了, 真好. 但這也表示所有 expression 的結果型別都不是唯一, 而必須是一個 Set... 我的程式有得改了 @_@ : 話說越寫越覺得跟我想做但是做不下去的 contraint existential types 很像 XD ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 這是什麼啊? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.32.132.21