Error: Type is not extensible?

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:

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

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

But still get the same error.

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

1 Like

How can I specify this?

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

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

  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?

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:

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:

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): ...
*)