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?
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With