reasonml

How do I declare a map type in Reason ML?

一个人想着一个人 提交于 2019-11-30 18:29:05
One advantage of Reason ML over JavaScript is that it provides a Map type that uses structural equality rather than reference equality. However, I cannot find usage examples of this. For example, how would I declare a type scores that is a map of strings to integers? /* Something like this */ type scores = Map<string, int>; And how would I construct an instance? /* Something like this */ let myMap = scores(); let myMap2 = myMap.set('x', 100); The standard library Map is actually quite unique in the programming language world in that it is a module functor which you must use to construct a map

How do I declare a map type in Reason ML?

只谈情不闲聊 提交于 2019-11-30 01:53:07
问题 One advantage of Reason ML over JavaScript is that it provides a Map type that uses structural equality rather than reference equality. However, I cannot find usage examples of this. For example, how would I declare a type scores that is a map of strings to integers? /* Something like this */ type scores = Map<string, int>; And how would I construct an instance? /* Something like this */ let myMap = scores(); let myMap2 = myMap.set('x', 100); 回答1: The standard library Map is actually quite