Question:
在DictByList的implement方法下,定義了modify函式如下: fun modify (i,l) x a = ... 這個函式把它獨立出來和property list做測試,可以正確的修改題目所定義的property list 可是type inference的結果是:''a * (string * ''a) list -> string -> ''a -> ''a * (string * ''a) list 定義的'a state為'a * (string * 'a) list) 所以放在structure裡就有型態不符合的問題... 想問老師: 'a 和 ''a 的差別在哪裡呢?為什麼ML的type inference會有這樣的結果?
Answer:
請見作業三 Q&A的最後問答部份。
Question:
關於作業第五題 ex11.4 的(a)小題的 Figure P.11.4.1 到底在哪裡?
Answer:
再翻過一頁,在 p. 330 。
Question:
還是不太懂opaque signature matching的用法 只大概知道它可以拿來做一些type checking的修正 但也不知道為什麼有必要這樣 可以請老師說明一下嗎?
Answer:
以下的 structure DictByList 的定義: structure DictByList: DICTIONARY = struct type 'a state = 'a * (string * 'a) list fun init i = ... fun modify (i, l) x a = ... fun lookup (i, l) x = ... end 用到了 signature DICTIONARY ,且 DICTIONARY 要求必須有一個型態 'a state (但不要求說出這個型態的製作方式)。 但實際在使用 DictByList 的時候,型態 'a state 的定義(製作方式) type 'a state = 'a * (string * 'a) list 卻會揭露給 DictByList 的使用者,你覺得這是好的嗎? 例如:使用者可以識破 DictByList 的製作方式,寫以下的程式: val k = (0, []): int DictByList.state; 這是好的嗎?