# About Ocaml list type

**URL:** https://discuss.ocaml.org/t/about-ocaml-list-type/5443
**Category:** Learning
**Created:** [April 4, 2020, 3:10pm UTC](https://discuss.ocaml.org/t/about-ocaml-list-type/5443 "2020-04-04T15:10:52Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![hss](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/hss/32/1489_2.png) [@hss](https://discuss.ocaml.org/u/hss)
#### Post date: [April 4, 2020, 3:10pm UTC](https://discuss.ocaml.org/t/about-ocaml-list-type/5443/1 "2020-04-04T15:10:52Z")

</div>

Hi 🙂

I’m a student who is learning OCaml language. I saw the implementation of type of list which is built-in type in OCaml

```auto
type 'a t = 'a list =
| []
| :: of 'a * 'a list

```

I have two questions:

1. When I copy and paste whole code above in OCaml interpreter, an error is occurred with “syntax error” I think `::` is a reason but the implementation uses `::`. how does it work? and how can I execute?
2. Where is the `list`? the name of the type is `t`, not `list`. where information of list is in?

Thank you.

---

<div class="post-metadata">

### Author: ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)
#### Post date: [April 4, 2020, 4:10pm UTC](https://discuss.ocaml.org/t/about-ocaml-list-type/5443/2 "2020-04-04T16:10:15Z")

</div>

Hello! Can I ask, where did you see that list implementation? In other words, where is that code from? It is indeed incorrect, the correct version is at [https://github.com/ocaml/ocaml/blob/1d76e2ca91633ac63759c4672e9a8dddabac8a31/stdlib/list.ml#L17](https://github.com/ocaml/ocaml/blob/1d76e2ca91633ac63759c4672e9a8dddabac8a31/stdlib/list.ml#L17) which is using valid syntax.

The difference is that `::` is considered an ‘operator’ as well as being a variant constructor, and thus needs to be defined using parentheses: `(::)`.

As to your second question: `list` is a built-in type that is always available. The `Stdlib.List` module is aliasing the definition of the `list` type and calling it `t`, because in OCaml it’s customary for data types to be in their own modules and the actual types to be named `t`. There are a few exceptions, like `list`, `option`, etc. but some efforts are being made as you see to alias them into a more idiomatic module and naming convention.

---

<div class="post-metadata">

### Author: ![hss](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/hss/32/1489_2.png) [@hss](https://discuss.ocaml.org/u/hss)
#### Post date: [April 4, 2020, 5:40pm UTC](https://discuss.ocaml.org/t/about-ocaml-list-type/5443/4 "2020-04-04T17:40:59Z")

</div>

Thanks for grate explanation!

I saw the implementation here : [https://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html](https://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html)

---

<div class="post-metadata">

### Author: ![hss](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/hss/32/1489_2.png) [@hss](https://discuss.ocaml.org/u/hss)
#### Post date: [April 4, 2020, 5:52pm UTC](https://discuss.ocaml.org/t/about-ocaml-list-type/5443/5 "2020-04-04T17:52:04Z")

</div>

Can I do one more question?

`type a = (::) of int * int ;;` is OK.

`type a = (##) of int * int ;;` is NOT OK.  
`type a = ($$) of int * int ;;` is NOT OK.  
`type a = (%%) of int * int ;;` is NOT OK… so on

Is there a rule for operator? why `::` is allowed but others are not allowed ?

---

<div class="post-metadata">

### Author: ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)
#### Post date: [April 4, 2020, 6:34pm UTC](https://discuss.ocaml.org/t/about-ocaml-list-type/5443/6 "2020-04-04T18:34:16Z")

</div>

`::` is one of a few exceptional operators that are allowed to be variant constructors in OCaml, I believe the others are `[]`, `()`, `true`, and `false` (well the last two are not really operators but they fall into the same syntactic area when it comes to being variant constructors).

Other than the above, variant constructors must be alphanumeric and start with an uppercase letter.

---

<div class="post-metadata">

### Author: ![hss](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/hss/32/1489_2.png) [@hss](https://discuss.ocaml.org/u/hss)
#### Post date: [April 5, 2020, 4:46am UTC](https://discuss.ocaml.org/t/about-ocaml-list-type/5443/7 "2020-04-05T04:46:43Z")

</div>

Thank you very much 🙂
