# Error: Type is not extensible?

**URL:** <https://discuss.ocaml.org/t/error-type-is-not-extensible/4176>\
**Category:** Learning\
**Created:** [July 30, 2019, 8:24am UTC](https://discuss.ocaml.org/t/error-type-is-not-extensible/4176 "2019-07-30T08:24:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarcCoquand](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/marccoquand/32/4901_2.png) [@MarcCoquand](https://discuss.ocaml.org/u/MarcCoquand)\
**Post date:** [July 30, 2019, 8:24am UTC](https://discuss.ocaml.org/t/error-type-is-not-extensible/4176/1 "2019-07-30T08:24:00Z")

</div>

Hello, I’ve declared a massive GADT in one file and I’d like to extend it in another module in another file by doing the following:

```auto
type Spec.Router.t('a,'b) += NewCase: Spec.Router.t(int,int)

```

however I get the error `Error: Type Spec.Router.t is not extensible`. I tried to add a default case to all the functions that use it

```auto
      | _ => raise(ParseExn("Invalid constructor"))

```

But still get the same error.

---

<div class="post-metadata">

**Author:** ![Armael](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/armael/32/1223_2.png) [@Armael](https://discuss.ocaml.org/u/Armael)\
**Post date:** [July 30, 2019, 8:43am UTC](https://discuss.ocaml.org/t/error-type-is-not-extensible/4176/2 "2019-07-30T08:43:20Z")

</div>

What does the signature of `Spec.Router` says about `t`?  
It needs to export the fact that `t` is extensible.

---

<div class="post-metadata">

**Author:** ![MarcCoquand](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/marccoquand/32/4901_2.png) [@MarcCoquand](https://discuss.ocaml.org/u/MarcCoquand)\
**Post date:** [July 30, 2019, 9:30am UTC](https://discuss.ocaml.org/t/error-type-is-not-extensible/4176/3 "2019-07-30T09:30:54Z")

</div>

How can I specify this?

---

<div class="post-metadata">

**Author:** ![Armael](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/armael/32/1223_2.png) [@Armael](https://discuss.ocaml.org/u/Armael)\
**Post date:** [July 30, 2019, 9:33am UTC](https://discuss.ocaml.org/t/error-type-is-not-extensible/4176/4 "2019-07-30T09:33:36Z")

</div>

Just like in the implementation, `type t ('a,'b) = ..` .

---

<div class="post-metadata">

**Author:** ![MarcCoquand](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/marccoquand/32/4901_2.png) [@MarcCoquand](https://discuss.ocaml.org/u/MarcCoquand)\
**Post date:** [July 30, 2019, 10:08am UTC](https://discuss.ocaml.org/t/error-type-is-not-extensible/4176/5 "2019-07-30T10:08:20Z")

</div>

All right, currently it’s declared like this (ReasonML syntax):

```auto
  type t('a, 'b) =
    | Top: t(('a, 'a), ('a, 'a))
    | Exact(string): t(('a, 'b), ('a, 'b))
    | ...

```

Do you mean that this needs to be exposed in the rei/mli file?

---

<div class="post-metadata">

**Author:** ![Armael](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/armael/32/1223_2.png) [@Armael](https://discuss.ocaml.org/u/Armael)\
**Post date:** [July 30, 2019, 11:38am UTC](https://discuss.ocaml.org/t/error-type-is-not-extensible/4176/6 "2019-07-30T11:38:16Z")

</div>

If I understand correctly, your declaration for type `t` is a standard variant definition, and is therefore _not_ extensible. Instead, your .re file should contain:

```ocaml
type t('a, 'b) = ..
type t('a,'b) +=
  | Top: t(('a, 'a), ('a, 'a))
  | Exact(string): t(('a, 'b), ('a, 'b))
  | ...

```

and in the .rei file, you need to at least include the first line to export the fact that `t` is extensible:

```ocaml
type t('a, 'b) = ..
(* you can also include the constructor declarations of the .re file 
    if you want to make the constructors Top and Exact public. 
type t('a, 'b) +=
  | Top: ...
  | Exact(string): ...
*)

```
