Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7413639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:56:19+00:00 2026-05-29T06:56:19+00:00

I am still struggling with my design and implementation, thought it progresses… First, I

  • 0

I am still struggling with my design and implementation, thought it progresses…

First, I have defined 2 basic signatures and 2 modules:

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

Then I have defined 3 signatures, 3 functors and applied them with the basic modules above:

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)

Actually I need to define a function f: AreaMmmArray.t -> ViDbmArray.t -> AreaMmmArray.t * ViDbmArray.t which requires another function g: 'a Mmm.t -> 'a Matrix.t -> 'a Mmm.t * 'a Matrix.t. As it involves the types of several parallel modules, my major question is in which modules I should define them.

In the code above, as a try, I have implemented f in ViDbmFun and g in AMatrixFun. The compilation stops at (AMatrixArray.g mmm dbm); and gives me:

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

I think the error is reasonable, because int Mmm.t in AreaMmmFun may be something other than MmmArray.t forced in AMatrixArray… Is there a way to work around this?

Again, I think the major question is where to define f and g, could anyone help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:56:20+00:00Added an answer on May 29, 2026 at 6:56 am

    I’d say you are not at the right level of definition indeed. Matrix and Mmm are independent, and put together to make an AMatrix. Here you try to define a function that speaks about bothMatrixandMmmin aFooMmmFunfunctor, which only knows aboutMmm, notMatrix; using the particular instanceMatrixArray` is not the solution, and you get a type error trying to do that.

    You have to define f at a level that knows about both Matrix (or ViDbm) and Mmm (or AreaMmm). Here is my suggestion, to add to your code after the declaration of the AREAMMM signature. It mostly define a functorized layer for AMatrix, as you did for Matrix and MMM.

    (* does not speak about `f` as no `Matrix` is available *)
    module AreaMmmFun (Mmm: MMM) : AREAMMM with module Mmm = Mmm = struct
      module Mmm = Mmm
      type t = | Mtop | Mbot | M of int Mmm.t
    end
    module AreaMmmArray  = AreaMmmFun(MmmArray)
    
    (* a functor over `AMatrix`, that knows both `Matrix` and `Mmm`,
       so we can define `f` here. I don't know which signature you want. *)
    module AMatrixFun (AMatrix : AMATRIX)
    = struct
      module ViDbm = ViDbmFun(AMatrix.Matrix)
      module AreaMmm = AreaMmmFun(AMatrix.Mmm)
    
      let f (am: AreaMmm.t) (vd: ViDbm.t) : AreaMmm.t * ViDbm.t =
        let (AreaMmm.M mmm), (ViDbm.D dbm) = am, vd in
        (AMatrix.g mmm dbm);
        failwith "to do"
    end
    
    module AmatrixFooArray = AMatrixFun(AMatrixArray)
    

    PS: you could define a parametric type for types closed by top/bottom, to avoid duplication of constructor names. Outside of any module:

    type 'a order = Top | Bot | D of 'a
    

    Then you can define VIDBM.t as int Matrix.t order, and AREAMMM.t as int Mmm.t order, instead of having two incompatible types and families of constructors (Mtop, Dtop…).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still struggling with my design and implementation of modules, I have defined
I'm still struggling with this concept. I have two different Person objects, very simply:
still struggling with regex :) i have this code: $link = '/\bhttp:\/\/.+\..+[\/\w]?\b/i'; $match =
I am still struggling with understanding classes, I am not certain but I have
This is a rather basic question, however I'm still struggling with it a little.
While I'm still struggling to find a solution for this question, i have another
I'm still struggling with my scenario. I have looked everywhere for a solution and
I'm still struggling with what must be basic (and resolved) issues related to CQRS
I am still struggling with drawing a line with CGContext. I have actually go
I've looked at the RFC but I am still struggling. I've written a basic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.