Can't apply interface because it is unbound?


#1

Hello. I’ve got an interface (databsase.rei) and am trying to apply that interface to a module (pouchDb.re) but I’m getting an error on line 1 of the implementation file: “The error is “Unbound module type DatabaseInterface”.”

Here’s the line that is failing: module PouchDb: DatabaseInterface = {

Any ideas?

My interface is here: https://github.com/bsommardahl/cafe-frontend/blob/master/src/database.rei
My implementation is here: https://github.com/bsommardahl/cafe-frontend/blob/master/src/pouchdb.re


#2

Reason automatically converts .re files into modules and .rei files into interfaces; explicitly defining modules and interfaces inside those files means adding a level of nested modules and interfaces. So, you’ll need to access nested items inside modules using dot-notation. Try this:

/* Interface.re */
module type Database = {
  module DatabaseInfo: ... = ...;
  module RevResponse: ... = ...;
  /* ... rest of the module type ... */
};

/* PouchDb.rei */
include Interface.Database;

/* PouchDb.re */
type t;
module DatabaseInfo = ...;
module RevResponse = ...;
/* ... rest of the file ... */

Since the compiler will automatically constrain .re files to interfaces specified in their corresponding .rei files, you can set up the PouchDb.rei file to just be an ‘inclusion’ of the Dabatase interface, which means they are semantically the same interface.

You can do the same thing for FakePouchDb.re.

Original idea from https://blog.janestreet.com/simple-top-down-development-in-ocaml/