我打算在Ocaml中使用Map
來練習。如何使用Map /定義一個實際上是OCaml中的Map的類型?
我發現Map
的用法是從List
,Array
完全不同,等
我的理解是運用functor
,我還沒有學會。但沒關係。
這裏是我的IntMap
module IntMap = Map.Make(struct type t = int let compare = compare end)
所以,現在我可以IntMap.add x y map
使用IntMap
到add
等,對不對?
我有幾個問題:
- 如何控制
value
在map
類型? - 如果我想要我的
IntMap
的別名類型,我該怎麼辦?我可以做type 'a my_type = 'a list
,但map
怎麼辦? - 我發現
IntMap
就像List
,他們兩個實際上都是modules
。但List
有一種類型list
,那麼map
呢?
我在doc中看到'type +'a t類型鍵到類型'a'的映射類型,裏面的'+'的含義是什麼? – 2013-04-04 16:25:37
@JacksonTale看到這個問題:[爲什麼在此類型之前有一個加號?](http://stackoverflow.com/questions/15305499/why-there-is-a-plus-sign-before-this-type/ ) – gasche 2013-04-04 21:46:52