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

The Archive Base Latest Questions

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

I need a function that returns a List < List < T>>. The value

  • 0

I need a function that returns a List < List < T>>.
The value i j should be 1.0 or 2.0 or nothing..depending on certain conditions (condition_1_is_true …).

I’ve written the following :

type T = 
  {
     value : float32
  }
let level_1_docked_balls : List<List<T>>=
    [ for i in 0 .. LineNumber - 1->
        [ for j  in 0 .. BallsPerLine - 1 ->

            if (condition_1_is_true) then
                {
                   value = 1.0f
                }
            elif (condition_2_is_true) then
                {
                    value = 2.0f
                }
            else
                //HERE I don't know how to return nothing

        ]
    ]

The problem is that in certain cases (else branch), I need to return nothing, but I don’t know how to do it.

NOTE: I know that there are eventually better ways to initialize a List but I would like to understand how to make the above example work.

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

    You probably want something like:

    let level_1_docked_balls : List<List<option<float32>>> = 
        [ for i in 0 .. LineNumber - 1 -> 
            [ for j  in 0 .. BallsPerLine - 1 -> 
                if (condition_1_is_true) then Some 1.0f 
                elif (condition_2_is_true) then Some 2.0f 
                else None ]  ] 
    

    There is no way to say that there is nothing at a specified index in the list. A list is simply a list of values and if you didn’t return a value, then the list would be shorter. If you want to represent float or nothing, then you can use F# option type – the value Some 1.0f specifies that there is a value 1.0f and the value None specifies that there is no number at that position.

    I also changed the type from float to float32 in the type annotation. The type float32 corresponds to System.Single and the literals are written as 1.0f. The other option is double (float with literals 1.0).

    As a side-note, if you’re representing some 2D matrix and especially if you need to access value at a specified index, then it is probably better to use 2D array. Although they are mutable, you can use them in an immutable way using higher-order functions like Array2D.map. To create a 2D array similar to your list, you could write:

    let level1 = Array2D.init LineNumber BallsPerLine (fun i j ->
      if (condition_1_is_true) then Some 1.0f 
      elif (condition_2_is_true) then Some 2.0f 
      else None)
    

    EDIT There are two options to represent something like balls in a map of a game. Either use dense representation where you have some value for each (i, j) – that’s what I described earlier. Another option is to use sparse representation where you only keep a list of balls, together with the (i, j) index where the ball is located. Then you could write something like:

    let level_1_docked_balls : List<int * int * float32> = 
        [ for i in 0 .. LineNumber - 1 do
            for j  in 0 .. BallsPerLine - 1 do
              if (condition_1_is_true) then yield (i, j, 1.0f)
              elif (condition_2_is_true) then yield (i, j, 2.0f) ]
    

    When you use do in the for loop, then you can write yield to generate an element, but you don’t have to return a value in each case — there is no else branch. However, you need to know the index where the value belongs.

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

Sidebar

Related Questions

I need a function that returns the ASCII value of a character, including spaces,
I need a function count_permutations() that returns the number of permutations of a given
I need to make a stored procedure or function that returns a set of
Need a function that takes a character as a parameter and returns true if
Need a function like: function isGoogleURL(url) { ... } that returns true iff URL
I have need for a function pointer that takes two arguments and returns a
I need to create a function that can takes a list of tuples and
I need to create a view or a table valued function that returns one
I need function count_sprintf() that should return number of characters (not inc nul byte)
I need to search a dblinq table so that the function should return the

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.