Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inheritance of modules and their type

I have defined 2 signatures and 2 modules as follows. One signature is derived from another; one module is derived from another.

module type MATRIX =
sig
  type 'a t
  ...
end

module type AMATRIX = 
sig
  include MATRIX
  ...
end

module MatrixArray : MATRIX =
struct
  type 'a t = 'a array array
  ...
end

module AMatrixArray : AMATRIX =
struct
  include MatrixArray
  let init (x: 'a) : 'a t =
    Array.make 2 (Array.make 2 x)
  ...
end

But when I compile this, it gives me an error in the end Error: This expression has type 'a array array but an expression was expected of type 'a t = 'a MatrixArray.t.

Does anyone know how I could keep this inheritance and make the type 'a t = 'a array array recognized?

like image 268
SoftTimur Avatar asked Jan 17 '23 15:01

SoftTimur


1 Answers

In the code:

module MatrixArray : MATRIX = struct
  type 'a t = 'a array array
 ...
end

You force MatrixArray to hide the definition of 'a t. One way to solve your problem is to remove the signature constraint:

module MatrixArray = struct
  type 'a t = 'a array array
 ...
end

You can later replace MatrixArray with (MatrixArray : MATRIX) when you want to abstract the type t.

like image 111
Thomas Avatar answered Jan 25 '23 23:01

Thomas