# Examples of using Base Map

**URL:** https://discuss.ocaml.org/t/examples-of-using-base-map/1197
**Category:** Learning
**Tags:** datastructures
**Created:** [November 27, 2017, 12:12pm UTC](https://discuss.ocaml.org/t/examples-of-using-base-map/1197 "2017-11-27T12:12:50Z")
**Posts on this page:** 10
**Page:** 2

<div class="post-metadata">

### Author: ![bluddy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bluddy/32/104_2.png) [@bluddy](https://discuss.ocaml.org/u/bluddy)
#### Post date: [December 4, 2017, 4:53pm UTC](https://discuss.ocaml.org/t/examples-of-using-base-map/1197/21 "2017-12-04T16:53:26Z")

</div>

> [@Yaron\_Minsky](#):
>
> I’m not especially compelled by the compatibility argument. After all, functor-specialized maps aren’t really natural as data-interchange types anyway.

I wasn’t talking about data compatibility here, but rather about the compatibility of Base with the rest of the ecosystem from the user’s perspective. Since the main introduction to OCaml is now RWO via Base/Core, the more incompatibilities a user encounters as he/she meets the rest of the OCaml ecosystem, the harder it’ll be for said user to become comfortable with OCaml. It feels like we’ve taken one step forward with jbuilder becoming the de facto build system, and then one step back with introducing this new break with the rest of the language.

As one potential example, a user coming to OCaml from RWO may be completely unfamiliar with applying functors since they’re essentially unnecessary in the new Base world. I realize that RWO covers them, but they’re not required for daily use in Base and so may be skipped, similar to the chapter on objects.

---

<div class="post-metadata">

### Author: ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)
#### Post date: [December 4, 2017, 6:30pm UTC](https://discuss.ocaml.org/t/examples-of-using-base-map/1197/22 "2017-12-04T18:30:59Z")

</div>

> [@bluddy](#):
>
> As one potential example, a user coming to OCaml from RWO may be completely unfamiliar with applying functors since they’re essentially unnecessary in the new Base world. I realize that RWO covers them, but they’re not required for daily use in Base and so may be skipped, similar to the chapter on objects.

I don’t think this is true. Using Base in a serious way pretty much requires the use of functors. Indeed, Maps in particular requires the use of Comparable.Make to build the modules that go into the first-class modules.

More generally, I don’t have a clear sense of what incompatibility you’re concerned about here.

y

---

<div class="post-metadata">

### Author: ![bluddy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bluddy/32/104_2.png) [@bluddy](https://discuss.ocaml.org/u/bluddy)
#### Post date: [December 4, 2017, 8:26pm UTC](https://discuss.ocaml.org/t/examples-of-using-base-map/1197/23 "2017-12-04T20:26:15Z")

</div>

> [@Yaron\_Minsky](#):
>
> Indeed, Maps in particular requires the use of Comparable.Make to build the modules that go into the first-class modules.

Good point. To be picky though, you can define the module using only a function (Comparator.make) and first-class modules.

> [@Yaron\_Minsky](#):
>
> More generally, I don’t have a clear sense of what incompatibility you’re concerned about here.

IMO, RWO is now _the_ main gateway into the language (the other one perhaps being ReasonML). I therefore think it’s useful to consider, when modifying Base/Core, whether it’s a good idea to switch paradigm to something that isn’t used by the rest of the community, because that’s the direction new users will follow. In the case of jbuilder, the new paradigm was clearly superior to everything that existed previously. I don’t care if new users aren’t familiar with the intricacies of \_tags files, because there’s pretty much no reason to go back to that Jurassic era. In the case of standard libraries, I’m concerned about introducing brand new paradigms. A conceptual compatibility that existed between the standard library and Core/Base has been removed by the switch to first class modules, and I don’t see the standard library following suite because the advantages of this approach aren’t overwhelming. So we’re dealing with a bigger inter-library chasm forming on the main path of new users to the language. I don’t expect Jane Street to change their approach here though – I’m just voicing my concern.

---

<div class="post-metadata">

### Author: ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)
#### Post date: [December 4, 2017, 9:21pm UTC](https://discuss.ocaml.org/t/examples-of-using-base-map/1197/24 "2017-12-04T21:21:41Z")

</div>

The philosophy behind Base is pretty clear: it’s not attempting to hew close to the stdlib, and really never has. Instead, it’s trying to cut clear, consistent, and useful APIs, and to do so in a way that minimizes the pain points and misfeatures of the language, like polymorphic comparison and hash functions.

People who want to maximize API similarity to the stdlib should likely look elsewhere.

---

<div class="post-metadata">

### Author: ![Levi\_Roth](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/levi_roth/32/2268_2.png) [@Levi\_Roth](https://discuss.ocaml.org/u/Levi_Roth)
#### Post date: [January 30, 2018, 4:49pm UTC](https://discuss.ocaml.org/t/examples-of-using-base-map/1197/25 "2018-01-30T16:49:50Z")

</div>

> [@Yaron\_Minsky](#):
>
> We’re working on it, and I also hope to refresh the chapter in RWO to cover the way Maps now work in Base (and will soon work in Core as well.)

Am I correct in understanding that things work this way in Core 0.10.0?

---

<div class="post-metadata">

### Author: ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)
#### Post date: [January 30, 2018, 6:11pm UTC](https://discuss.ocaml.org/t/examples-of-using-base-map/1197/26 "2018-01-30T18:11:12Z")

</div>

Yup. The documentation for 0.10 isn’t up yet, so I can’t point you at it, but it should be up in the next few days.

---

<div class="post-metadata">

### Author: ![trefis](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/trefis/32/837_2.png) [@trefis](https://discuss.ocaml.org/u/trefis)
#### Post date: [February 16, 2018, 2:43pm UTC](https://discuss.ocaml.org/t/examples-of-using-base-map/1197/27 "2018-02-16T14:43:44Z")

</div>

Note that the docs for v0.10 are now up, and that core\_kernel’s doc for Map includes some examples: [https://ocaml.janestreet.com/ocaml-core/latest/doc/core\_kernel/Core\_kernel/Map/](https://ocaml.janestreet.com/ocaml-core/latest/doc/core_kernel/Core_kernel/Map/)

---

<div class="post-metadata">

### Author: ![rauschma](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/rauschma/32/730_2.png) [@rauschma](https://discuss.ocaml.org/u/rauschma)
#### Post date: [February 23, 2018, 11:39pm UTC](https://discuss.ocaml.org/t/examples-of-using-base-map/1197/28 "2018-02-23T23:39:43Z")

</div>

Much nicer than Map.Make in the standard library!

What are the advantages of this approach, compared to simply storing functions `compare` and `sexp_of_t` in a record when creating a map (provided via parameters to `Map.empty()` etc.)?

---

<div class="post-metadata">

### Author: ![BikalGurung](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bikalgurung/32/5105_2.png) [@BikalGurung](https://discuss.ocaml.org/u/BikalGurung)
#### Post date: [February 24, 2018, 2:40am UTC](https://discuss.ocaml.org/t/examples-of-using-base-map/1197/29 "2018-02-24T02:40:29Z")

</div>

> compared to simply storing functions compare and sexp\_of\_t in a record when creating a map (provided via parameters to Map.empty() etc.)

That would most likely make the `Map` type unsound, especially when using `union/diff` functions. Base Map/Set nicely avoids that by minting fresh type on creation.

---

<div class="post-metadata">

### Author: ![rauschma](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/rauschma/32/730_2.png) [@rauschma](https://discuss.ocaml.org/u/rauschma)
#### Post date: [February 24, 2018, 4:14pm UTC](https://discuss.ocaml.org/t/examples-of-using-base-map/1197/30 "2018-02-24T16:14:43Z")

</div>

Ah, brilliant! One thing I initially overlooked is that the module is stored as a phantom type statically, which makes everything quite convenient.

[Previous page](https://discuss.ocaml.org/t/examples-of-using-base-map/1197.md?page=1)
