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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:47:33+00:00 2026-05-20T13:47:33+00:00

Can somebody give me an example of how to make inserting data into an

  • 0

Can somebody give me an example of how to make inserting data into an F# record more flexible?

I often see examples using records like this:

type Employee = {mutable name:string; mutable id:string}

let data = 
    [{name = "Thomas";id = "000"};
     {name = "Johny";id = "001"};
     {name = "Lucky";id = "002"};
     {name = "Don";id = "003"}
    ]

Can’t we start with no data at all and insert the data into the record later?

(What I mean is without declaration of the value of the data like in the example, so for example: the program is running and asking us to insert the data)

Can we doing something like this with record?

  • 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-20T13:47:34+00:00Added an answer on May 20, 2026 at 1:47 pm

    If you’re talking about specifying values of a record as they become available, then you need to make fields of the record option so that you can represent the fact that value is missing. I’ll use immutable records, because this is more common in functional style:

    type Employee = { Name:option<string>; ID:option<string> }  
    

    Now you can create a record with only ID and add name when the user enters it:

    let empty = { Name = None; ID = Some 123 }
    let name = // read name from user
    let full = { empty with Name = name }
    

    If you’re talking about adding items to a list as they become available, then you have several options. The direct one is to write a recursive function that repeatedly reads record and builds a list:

    let rec readData i records = 
      let name = // read name from user 
      if name <> "" then
        // Create new record and add it to our list
        let itm = { Name = name; ID = string i }
        readData (i + 1) (itm::records)
      else 
        // Return records that we collected so far in the right order
        records |> List.rev
    

    Alternatively, you can also use sequence expressions (see for example free Chapter 12 (PDF) of Real-World Functional Programming). If you user interaction involves waiting for events (e.g. mouse click), then you can still use this style, but you’d need to wrap everything in asynchronous workflow and use Async.AwaitEvent.

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

Sidebar

Related Questions

can somebody give a simple CGI primer using C++ or C for example? Let`s
Can somebody give me some tips about storing a lot of data into a
Can somebody please give me an example of a unidirectional @OneToOne primary-key mapping in
Can somebody give an example of opening asset file in apk, which is called
Can somebody give me an example how I can copy a file and open
Can somebody give me an example of how to add a tag to a
Can somebody give advice, how to test AJAX in Ruby on Rails? For example:
Can somebody give me a good example for Java CGLib Mixin class usage? I've
Can somebody give an example usage of pcrecpp DoMatch routine? Basically my requirement is
Somebody can give me an example to do this. Suppose static variable scope is

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.