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 4018624
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:00:22+00:00 2026-05-20T10:00:22+00:00

I have created the following type using implicit type construction: open System type Matrix(sourceMatrix:double[,])

  • 0

I have created the following type using implicit type construction:

open System

type Matrix(sourceMatrix:double[,]) =
  let rows = sourceMatrix.GetUpperBound(0) + 1
  let cols = sourceMatrix.GetUpperBound(1) + 1
  let matrix = Array2D.zeroCreate<double> rows cols
  do
    for i in 0 .. rows - 1 do
    for j in 0 .. cols - 1 do
      matrix.[i,j] <- sourceMatrix.[i,j]

  //Properties

  ///The number of Rows in this Matrix.
  member this.Rows = rows

  ///The number of Columns in this Matrix.
  member this.Cols = cols

  ///Indexed Property for this matrix.
  member this.Item
    with get(x, y) = matrix.[x, y]
     and set(x, y) value = 
        this.Validate(x,y)
        matrix.[x, y] <- value

  //Methods
  /// Validate that the specified row and column are inside of the range of the matrix.
  member this.Validate(row, col) =
    if(row >= this.Rows || row < 0) then raise (new ArgumentOutOfRangeException("row is out of range"))
    if(col >= this.Cols || col < 0) then raise (new ArgumentOutOfRangeException("column is out of range"))

However now I need to add the following overloaded constructor to this type (which is in C# here):

public Matrix(int rows, int cols)
    {
        this.matrix = new double[rows, cols];
    }

The problem that I have is that it seems any overloaded constructors in an implicit type must have a parameter list that is a subset of the first constructor. Obviously the constructor I want to add does not meet this requirement. Is there any way to do this using implicit type construction? Which way should I do this? I’m pretty new to F# so if you could show the whole type with your changes in it I would greatly appreciate it.

Thanks in advance,

Bob

P.S. If you have any other suggestions to make my class more in the functional style please feel free to comment on that as well.

  • 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-20T10:00:22+00:00Added an answer on May 20, 2026 at 10:00 am

    I would probably just do this:

    type Matrix(sourceMatrix:double[,]) =
      let matrix = Array2D.copy sourceMatrix
      let rows = (matrix.GetUpperBound 0) + 1
      let cols = (matrix.GetUpperBound 1) + 1
    
      new(rows, cols) = Matrix( Array2D.zeroCreate rows cols )
    

    unless we are talking about very large arrays which are created very often (i.e. copying the empty array becomes a performance bottleneck).

    If you want to emulate the C# version, you need an explicit field that can be accessed from both constructors, like so:

    type Matrix(rows,cols) as this =
    
      [<DefaultValue>]
      val mutable matrix : double[,]
      do this.matrix <- Array2D.zeroCreate rows cols
    
      new(source:double[,]) as this =
        let rows = source.GetUpperBound(0) + 1
        let cols = source.GetUpperBound(1) + 1
        Matrix(rows, cols)
        then
          for i in 0 .. rows - 1 do
            for j in 0 .. cols - 1 do
              this.matrix.[i,j] <- source.[i,j]
    

    BTW, there is also a matrix type in the F# PowerPack.

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

Sidebar

Related Questions

I have created a custom content type and using views2 for creating various page-views.
I have successfully created the message queue by using the following command: msgIdHareTurtle =
So I have the following user defined type in my oracle database: CREATE OR
I have created the following stored procedure.. CREATE PROCEDURE [dbo].[UDSPRBHPRIMBUSTYPESTARTUP] ( @CODE CHAR(5) ,
I have created UITableCellView class called NoteCell . The header defines the following: #import
I have the following database table created thus: CREATE TABLE AUCTIONS ( ARTICLE_NO VARCHAR(20),
I'm using Entity Framework and I have created an interface for lease transactions: public
Using Microsoft's designer for the Entity Framework (v3.5), I have created an Entity Model
I'm using Zend, a PHP library, to work with Amazon EC2. I have created
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)

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.