Is it possible to create annoymous module?

I am writing a module like this.

module type MInt = {
  let width: int
}

module MakeInt = (I: MInt) => {
  let carry = lsl(1, I.width)
  let mask = lsl(1, I.width) - 1
  let neg = num => land(-num, mask)
  let add_and_carry = (a, b) => {
    let sum = a + b
    (land(sum, mask), sum / carry)
  }
  let add = (a, b) => {
    let (x, _) = add_and_carry(a, b)
    x
  }
  let sub = (a, b) => {
    add(a, neg(b))
  }
}
module A: MInt = {
  let width = 8
}
module I8 = MakeInt(A)
module B: MInt = {
  let width = 16
}
module I16 = MakeInt(B)

The module name A and B is redundant, is it possible to create an annoymous module just like OCaml do?

OCaml can create module like this:

module I8 = MakeInt(module struct let width = 8 end)

Yes, you can create an anonymous module like this:

module I8 = MakeInt({
  let width = 8
})
5 Likes