# Where/how is never\_returns defined?

**URL:** <https://discuss.ocaml.org/t/where-how-is-never-returns-defined/4086>\
**Category:** Learning\
**Created:** [July 11, 2019, 4:28pm UTC](https://discuss.ocaml.org/t/where-how-is-never-returns-defined/4086 "2019-07-11T16:28:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![atagunov](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/atagunov/32/2691_2.png) [@atagunov](https://discuss.ocaml.org/u/atagunov)\
**Post date:** [July 11, 2019, 4:28pm UTC](https://discuss.ocaml.org/t/where-how-is-never-returns-defined/4086/1 "2019-07-11T16:28:47Z")

</div>

Hi, noob here

- how does one generally define an uninhabited type like `never_returns`?
- where is `never_returns` itself defined?

Searching online and on `github` did not help…

---

<div class="post-metadata">

**Author:** ![bcc32](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bcc32/32/203_2.png) [@bcc32](https://discuss.ocaml.org/u/bcc32)\
**Post date:** [July 11, 2019, 5:11pm UTC](https://discuss.ocaml.org/t/where-how-is-never-returns-defined/4086/2 "2019-07-11T17:11:24Z")

</div>

I assume you’re referring to `Core.never_returns`? It is defined as an [empty variant type](https://caml.inria.fr/pub/docs/manual-ocaml-4.08/manual043.html):

```ocaml
type t = |

```

[https://github.com/janestreet/core\_kernel/blob/master/src/never\_returns.ml](https://github.com/janestreet/core_kernel/blob/master/src/never_returns.ml) shows the definition of `never_returns`, which is an alias to `Nothing.t`: [https://github.com/janestreet/core\_kernel/blob/master/src/nothing.mli](https://github.com/janestreet/core_kernel/blob/master/src/nothing.mli).

Trivia: before the introduction of empty variant types, `Nothing.t` used to be defined as a `(unit, int) Type_equal.t`, which can be made uninhabitable using GADT features:

> <https://github.com/janestreet/core_kernel/commit/f1abb34ca9cece959de0843f13cc8f648f339c04#diff-3ad0a754402aeef351cb6f855285c6ae>

---

<div class="post-metadata">

**Author:** ![atagunov](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/atagunov/32/2691_2.png) [@atagunov](https://discuss.ocaml.org/u/atagunov)\
**Post date:** [July 11, 2019, 5:29pm UTC](https://discuss.ocaml.org/t/where-how-is-never-returns-defined/4086/3 "2019-07-11T17:29:43Z")

</div>

Thx a bunch @bcc32! Nice avatar 😉

If I can pick your brain a bit more, how do I read

```auto
type t = |
val unreachable_code : t -> _

```

or for that matter the older version of

```auto
 let unreachable_code = function
      | (_ : t) -> .
    ;;

```

this underscore and this dot… what do they even mean?..

compiler figures out the type is uninhabited and they are just some kind of placeholders? but why two of them? `_` and `.` ?

…and finally was it some sort of a convention in old times to use `;;` in `.ml` files? These days I understand `;;` are only used in interactive top level?..

---

<div class="post-metadata">

**Author:** ![bcc32](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bcc32/32/203_2.png) [@bcc32](https://discuss.ocaml.org/u/bcc32)\
**Post date:** [July 11, 2019, 6:42pm UTC](https://discuss.ocaml.org/t/where-how-is-never-returns-defined/4086/4 "2019-07-11T18:42:12Z")

</div>

The underscore and dot are called a [refutation case](https://caml.inria.fr/pub/docs/manual-ocaml-4.08/manual033.html#sec259). It basically asks the compiler to check that the pattern cannot be inhabited.

`;;` is still common in ml files, but they are optional. One advantage is that they prevent a trailing `;` from producing a syntax error very far away from where the fix needs to be:

```ocaml
let f x =
  <many lines of code>;
  last statement;

let g x =
  <many more lines of code>

let h x =
^ syntax error reported here

```

---

<div class="post-metadata">

**Author:** ![atagunov](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/atagunov/32/2691_2.png) [@atagunov](https://discuss.ocaml.org/u/atagunov)\
**Post date:** [July 11, 2019, 9:49pm UTC](https://discuss.ocaml.org/t/where-how-is-never-returns-defined/4086/5 "2019-07-11T21:49:01Z")

</div>

ahh… finally got it… [nothing.mli](https://github.com/janestreet/core_kernel/blob/master/src/nothing.mli) says

```auto
val unreachable_code : t -> _

```

while [nothing.ml](https://github.com/janestreet/core_kernel/blob/master/src/nothing.ml) says

```auto
let unreachable_code = function
  | (_ : t) -> .
;;

```

and the resulting type of `unreachable_code` according to `utop` is

```auto
Core.Nothing.t -> 'a

```

So that `_` in `.mli` seems to indicate that it can be any type… There probably is a clever name for such use of `_` and one day I’ll find it 🙂
