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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:40:42+00:00 2026-05-27T07:40:42+00:00

Two functions are defined: let to2DStrArray (inObj : string[][]) = Array2D.init inObj.Length inObj.[0].Length (fun

  • 0

Two functions are defined:

let to2DStrArray (inObj : string[][]) = 
    Array2D.init   inObj.Length inObj.[0].Length (fun i j -> inObj.[i].[j])                            

let toTypedList typeFunc (strArray : string[,]) =
    if (Array2D.length1 strArray) = 0 then 
        []
    else
        List.init (Array2D.length1 strArray) typeFunc

trying to call them from fsx as follows fails:

    let testData = to2DStrArray [|[||]|] 
    let failingCall =   testData
                        |> toTypedList (fun row -> (Double.Parse(testData.[row,0]),
                                    Double.Parse(testData.[row,1])))

What is a working/better way to get this code to handle the case of empty 2-dimensional string arrays?

  • 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-27T07:40:43+00:00Added an answer on May 27, 2026 at 7:40 am

    The problem is not in toTypeList function so you don’t have to check whether strArray is empty or not. It will give an error if you check inObj.[0].Length in to2DStrArray function when the input array is empty. A safe way to create an Array2D from an array of array is using array2D operator:

    let to2DStrArray (inObj : string[][]) =
        array2D inObj
    

    Of course, you have to guarantee that all inner arrays have the same length. And the other function is shortened as follows:

    let toTypedList typeFunc (strArray : string[,]) =
        List.init (Array2D.length1 strArray) typeFunc
    

    Given your use case, note that [|[||]|] is not an empty string[][]; it is an array which consists of only one element which in turn is an empty string array. Therefore, it causes a problem for the anonymous function you passed to toTypedList. Since the two dimensional array has length2 <= 1 and you accesses two first indices, it results in an index of bound exception. The function could be fixed by returning option values, and you can extract values from option values to use later on:

    let testData = to2DStrArray [|[||]|] 
    let failingCall = testData                    
                      |> toTypedList (fun row -> if Array2D.length2 testData >= 2 then Some (Double.Parse(testData.[row,0]), Double.Parse(testData.[row,1])) else None)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
What is the difference between two functions in Scheme, one defined like this— (define
Let's say that I have two methods defined with the same name and return,
I'll try to explain with an example... Let's say I have two different functions,
The two functions in openCV cvLoadImage and cvSaveImage accept file path's as arguments. For
I've created two functions to load expanded views of a month in the archive
I have two functions to add and remove table rows that contain a form
I have two functions that have different enough logic but pretty much the same
I have two functions in an ActionScript class, they are: private function loaderCompleteHandler(event:Event):void {
Why this two functions have the strange behaviour of when I click on thead,

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.