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

  • SEARCH
  • Home
  • 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 7093857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:29:30+00:00 2026-05-28T08:29:30+00:00

I would like to build a general matrix module, which includes such general operations

  • 0

I would like to build a general matrix module, which includes such general operations as length, width, size, read_element, write_element, etc. As a matrix could be defined with several types: element array array, element list list or with map, the advantage of this module is to handle the details of the type of matrix inside it, and do not bother on the level where the module is called. At the moment, I think of something as follows:

module type A_TYPE =
  sig
    type t
  end;;

module matrix =
  functor (Elt: A_TYPE) 
  struct
    type element = Elt.t
    type t = element array array 
      (* `element list list` if I want a matrix to be a list of a list *)

    let length (m: t) : int =
       Array.length a
      (* `List.length a` if t = element list list *)

    ... ...

  end

So from outside, one can write:

module MyInt = struct type t = int end
module MatInt = Matrix(MyInt)
module MyFloat = struct type t = float end
module MatFloat = Matrix(MyFloat)

let m = MatInt.make 3 4 0
let n = MatFloat.make 3 4 0.2

My questions are:

1) I have to define first a module MyInt, then put it into the functor to create MatInt… I found it redundant… Is there a way to instantiate directly a matrix module whose elements have int as type?

2) Considering what is written in (* ... *), is there a way to implement the matrix module such that it handles at same time the different possibilities of type of a matrix? maybe with a pattern-matching?

Hope my questions are clear, 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-28T08:29:31+00:00Added an answer on May 28, 2026 at 8:29 am

    As for question #1: you don’t have to define a MyInt module, you could cut out that step by doing:

     module MatInt = Matrix(struct type t = int end)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to build some code which calls some code on loadup of
I would like to build an Erlang/OTP-based system which solves an 'embarassingly parrallel' problem.
I would like to build a regexp in Java that would be passed in
I would like to build an application that will run on a web, this
I would like to build a query that will pull the number of rows
I would like to build an excel VBA program to find all the match
I would like to build a static version of QT Library for X11 like
I would like to build a cross-platform GUI application in Python that displays PostScript
I would like to build some smaller scale but hightly customized documentation sites for
I would like to build a simple animation for a school project. I want

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.