# Defining Hashtbl variable

**URL:** https://discuss.ocaml.org/t/defining-hashtbl-variable/3516
**Category:** Learning
**Created:** [March 17, 2019, 8:16pm UTC](https://discuss.ocaml.org/t/defining-hashtbl-variable/3516 "2019-03-17T20:16:59Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![tangerhofer](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@tangerhofer](https://discuss.ocaml.org/u/tangerhofer)
#### Post date: [March 17, 2019, 8:16pm UTC](https://discuss.ocaml.org/t/defining-hashtbl-variable/3516/1 "2019-03-17T20:16:59Z")

</div>

I have been banging my head against a wall trying to figure out how to set a variable to be equal to a hashtable. I’m very new so this is probably a simple fix.

Here’s my function

```auto
let foo(_p1: float) (_p2:float): unit = 
    let table = Hashtbl.create 100 in
    (* ... *)
    print_endline "function end"

```

This doesn’t run without a warning of:  
“Error: This expression has type int but an expression was expected of type  
(module Base\_\_.Hashtbl\_intf.Key with type t = 'a)”

Any help would be greatly appreciated.  
Thanks.

---

<div class="post-metadata">

### Author: ![octachron](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@octachron](https://discuss.ocaml.org/u/octachron)
#### Post date: [March 17, 2019, 8:25pm UTC](https://discuss.ocaml.org/t/defining-hashtbl-variable/3516/2 "2019-03-17T20:25:48Z")

</div>

In `base`, `Hashtabl.create` takes a key module as argument, for instance:

```auto
let h = Hashtabl.create (module Int)

```

if you need `int` keys for instance.

---

<div class="post-metadata">

### Author: ![tangerhofer](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@tangerhofer](https://discuss.ocaml.org/u/tangerhofer)
#### Post date: [March 17, 2019, 8:39pm UTC](https://discuss.ocaml.org/t/defining-hashtbl-variable/3516/3 "2019-03-17T20:39:20Z")

</div>

Thanks for the response, that runs.

I’m still curious, however, why my solution didn’t work. I was trying to follow the syntax from [http://caml.inria.fr/pub/docs/manual-ocaml//libref/Hashtbl.html](http://caml.inria.fr/pub/docs/manual-ocaml//libref/Hashtbl.html)

Why doesn’t that work? By the way the only module I’m opening at the top of the file is Core. (I tried opening Hashtbl with no success)

---

<div class="post-metadata">

### Author: ![octachron](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@octachron](https://discuss.ocaml.org/u/octachron)
#### Post date: [March 17, 2019, 8:40pm UTC](https://discuss.ocaml.org/t/defining-hashtbl-variable/3516/4 "2019-03-17T20:40:54Z")

</div>

Core is a superset of Base which is itself an alternative standard library. The right documentation is here: [https://ocaml.janestreet.com/ocaml-core/latest/doc/base/Base/Hashtbl/index.html](https://ocaml.janestreet.com/ocaml-core/latest/doc/base/Base/Hashtbl/index.html) .

---

<div class="post-metadata">

### Author: ![tangerhofer](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@tangerhofer](https://discuss.ocaml.org/u/tangerhofer)
#### Post date: [March 17, 2019, 8:44pm UTC](https://discuss.ocaml.org/t/defining-hashtbl-variable/3516/5 "2019-03-17T20:44:50Z")

</div>

Got it, any idea where the [reference I posted](http://caml.inria.fr/pub/docs/manual-ocaml//libref/Hashtbl.html) comes from? Is that from a separate module I’d have to download if I wanted to use it?

---

<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: [March 17, 2019, 8:47pm UTC](https://discuss.ocaml.org/t/defining-hashtbl-variable/3516/6 "2019-03-17T20:47:36Z")

</div>

That is from the default standard library. In Core, you can access it via the `Caml` module; that is, as `Caml.Hashtbl`.

---

<div class="post-metadata">

### Author: ![threepwood](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@threepwood](https://discuss.ocaml.org/u/threepwood)
#### Post date: [March 18, 2019, 9:18am UTC](https://discuss.ocaml.org/t/defining-hashtbl-variable/3516/7 "2019-03-18T09:18:27Z")

</div>

To clarify what others have said : Core is a library. You `open` Core and (I presume) your `dune` file lists core as a package so when you use `Hashtbl` it means `Core.Hashtbl`. You don’t _have_ to use Core though, and if you didn’t `Hashtbl` would mean `Stdlib.Hashtbl`. The reference you’re linking is for the standard library, not for Core.

Most code you’ll in examples and discussion will be using standard library modules unless specified otherwise.

When Core is opened if you want to refer to standard library modules you need to use `Caml.List` etc., though perhaps with recent OCaml `Stdlib.List` works too.
