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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:35:00+00:00 2026-05-31T15:35:00+00:00

In F# array2Ds are mutable which doesn’t make for the most functional code. At

  • 0

In F# array2Ds are mutable which doesn’t make for the most functional code. At the moment, I’m hiding this by doing a Array2D.copy of my inputs when I want to make a change and return the array. i.e.

let test (x : int[,]) =
    let y = Array2D.copy x
    y.[0,0] <- 3

Is there a better approach that makes test more functional?

  • 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-31T15:35:02+00:00Added an answer on May 31, 2026 at 3:35 pm

    You can always use high-order functions on Array2D module to work with Array2D in a functional style. Particularly, Array2D.mapi operating on array indices is suitable for this task:

    let test (xs: int[,]) =
       xs |> Array2D.mapi (fun i j x -> if i=0 && j=0 then 3 else x) 
    

    EDIT:

    Generally speaking, your test function is fine since you can limit side effects inside the function only. You need to be more careful in the case of nested arrays; however, writing your own functions with controlled side effects usually gives better performance than using high-order functions for Array2D.

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

Sidebar

Related Questions

Consider the following code fragment in VS2010 Beta 1: let array = Array2D.zeroCreate 1000
I suspect that I am missing something very obvious here but this doesn't work:
I have an image which is representative of an Array2D: template<class T = uint8_t>
I came a across a new problem when using templates. This is me being
I'm trying to experiment with software defined radio concepts. From this article I've tried
im tunning this loop and what to populate the array with the output of
I'm fairly new the functional programming, so I'm going through some practice exercises. I
I have a matrix: Array2D and a function let DivideAndSubstract value index (matrix: float[,])
I currently have the following code: type Matrix(sourceMatrix:double[,]) = let rows = sourceMatrix.GetUpperBound(0) +
Is this function tail-recursive ? let rec rec_algo1 step J = if step =

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.