我仍然与我的设计和实现奋力内置2个并联模块,以为它的进展......定义功能在函子
首先,我已经定义了2个基本特征和2个模块:
module type MATRIX = sig type 'a t end
module MatrixArray: MATRIX = struct
type 'a t = 'a array array
end
module type MMM = sig type 'a t end
module MmmArray: MMM = struct
type 'a t = 'a array array
end
然后我定义了3个签名,3函子与施加将它们与基本模块以上:
module type AMATRIX = sig
include MATRIX
module Mmm : MMM
module Matrix: MATRIX
val g: 'a Mmm.t -> 'a Matrix.t -> 'a Mmm.t * 'a Matrix.t
end
module AMatrixFun (Mmm: MMM) (Matrix: MATRIX) : AMATRIX with module Mmm = Mmm and module Matrix = Matrix = struct
include MatrixArray
module Mmm = Mmm
module Matrix = Matrix
let g (mmm: 'a Mmm.t) (dbm: 'a Matrix.t) : 'a Mmm.t * 'a Matrix.t = failwith "to do"
end
module AMatrixArray = AMatrixFun(MmmArray)(MatrixArray)
module type VIDBM = sig
module Matrix: MATRIX
type t = | Dtop | Dbot | D of int Matrix.t
end
module ViDbmFun (Matrix: MATRIX) : VIDBM with module Matrix = Matrix = struct
module Matrix = Matrix
type t = | Dtop | Dbot | D of int Matrix.t
end
module ViDbmArray = ViDbmFun(MatrixArray)
module type AREAMMM = sig
module Mmm: MMM
type t = | Mtop | Mbot | M of int Mmm.t
end
module AreaMmmFun (Mmm: MMM) : AREAMMM with module Mmm = Mmm = struct
module Mmm = Mmm
type t = | Mtop | Mbot | M of int Mmm.t
let f (am: t) (vd: ViDbmArray.t) : t * ViDbmArray.t =
let (M mmm), (ViDbmArray.D dbm) = am, vd in
(AMatrixArray.g mmm dbm);
failwith "to do"
end
module AreaMmmArray = AreaMmmFun(MmmArray)
实际上我需要定义一个函数f: AreaMmmArray.t -> ViDbmArray.t -> AreaMmmArray.t * ViDbmArray.t
其需要另一个功能g: 'a Mmm.t -> 'a Matrix.t -> 'a Mmm.t * 'a Matrix.t
。由于它涉及几个并行模块的类型,我的主要问题是我应该在哪些模块中定义它们。
在上面的代码,作为一个尝试,我在ViDbmFun
和g
在AMatrixFun
实施f
。编译停在(AMatrixArray.g mmm dbm);
,给我:
Error: This expression has type int Mmm.t = int Mmm.t
but an expression was expected of type
'a AMatrixArray.Mmm.t = 'a MmmArray.t
我认为错误是合理的,因为在int Mmm.t
可以AreaMmmFun
比MmmArray.t
其他被迫AMatrixArray
东西...有没有办法解决呢?
同样,我认为主要的问题是在哪里定义f
和g
,有没有人可以帮忙?
您的示例中缺少模块'Mmt'。 – nlucaroni 2012-02-01 20:49:21
对不起,应该是'嗯',我已经修好了...... – SoftTimur 2012-02-01 20:56:57