# How to achieve \`type t = t\`?

**URL:** <https://discuss.ocaml.org/t/how-to-achieve-type-t-t/1449>\
**Category:** Learning\
**Created:** [January 20, 2018, 1:12am UTC](https://discuss.ocaml.org/t/how-to-achieve-type-t-t/1449 "2018-01-20T01:12:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjambon](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mjambon/32/6180_2.png) [@mjambon](https://discuss.ocaml.org/u/mjambon)\
**Post date:** [January 20, 2018, 1:12am UTC](https://discuss.ocaml.org/t/how-to-achieve-type-t-t/1449/1 "2018-01-20T01:12:51Z")

</div>

I’m wondering how to create a type alias for a type of the same name. This problem arises in the following scenario:

```auto
type t = A | B
module M = struct
  type t = t (* Error: The type abbreviation t is cyclic *)
end

```

A solution is to create a `t'` alias:

```auto
type t = A | B
type t' = t
module M = struct
  type t = t' (* works *)
end

```

Is there a better (clearer) solution which wouldn’t involve creating an extra type alias? I vaguely remember that there might be a clean solution but I couldn’t find it.

---

<div class="post-metadata">

**Author:** ![mjambon](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mjambon/32/6180_2.png) [@mjambon](https://discuss.ocaml.org/u/mjambon)\
**Post date:** [January 20, 2018, 1:17am UTC](https://discuss.ocaml.org/t/how-to-achieve-type-t-t/1449/2 "2018-01-20T01:17:21Z")

</div>

I found it [here](https://blog.janestreet.com/ocaml-annoyance-23-type-declarations-are-implicitly-recursive/) by googling the error message.

The solution is:

```auto
type t = A | B
module M = struct
  type nonrec t = t
end

```

(since ocaml 4.02.2)

---

<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:** [January 20, 2018, 2:28am UTC](https://discuss.ocaml.org/t/how-to-achieve-type-t-t/1449/3 "2018-01-20T02:28:19Z")

</div>

Prior to OCaml 4.02.2, you could have done instead:

```ocaml
type t = A | B
module M = struct
  type dummy = t
  type t = dummy
end

```
