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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:09:49+00:00 2026-05-28T03:09:49+00:00

Want to convert some C# code for RX to F# code. The following C#

  • 0

Want to convert some C# code for RX to F# code.
The following C# code works well:

  var seqNum = Observable.Range(1, 5);
  var seqString = from n in seqNum
                  select new string('*', (int)n);
  seqString.Subscribe(str => { Console.WriteLine(str); });
  Console.ReadKey();

The following is my code in F#:

#light
open System
open System.Collections.Generic
open System.Linq
open System.Reactive
open System.Reactive.Linq
open System.Reactive.Subjects
open System.Threading
open System.IO

let seqNum = Observable.Range(1, 5)
let seqString = from n in seqNum
                select new string('*', (int)n)
Console.ReadLine() |> ignore

But I got the following compiler error:
Error: Unexpected keyword ‘new’ in implementation file

If I deleted the new keyword, I got another error:
Error: Successive arguments should be separated by spaces or tupled, and arguments involving function or method applications should be parenthesized

The “new” keyword are totally different in C# and F#.
Please show me how to do the same job in F#.
Thanks,

  • 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-28T03:09:50+00:00Added an answer on May 28, 2026 at 3:09 am

    Here you go:

    open System
    open System.IO
    open System.Reactive
    open System.Reactive.Linq
    
    let seqString = Observable.Range(1,5).Select(fun x -> String.replicate x "*")
    using (seqString.Subscribe (fun x -> printfn "%s" x))
        (fun _ -> Console.ReadLine() ) |> ignore
    

    EDIT: As Paul suggested below two last lines can be replaced by simple

    seqString.Subscribe (printfn "%s") |> ignore
    

    However, if we want to gracefully unsubscribe from our subscription, but get rid of using in lieu of newer use syntax we may replace last two lines by the following three

    do
        use subscription = seqString.Subscribe(printfn "%s")
        Console.ReadLine() |> ignore
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to convert the following code to ActionScript (mxml works fine): <mx:Panel title=Some
I want to convert some VB.NET code for regular expression to F#. The following
I want to do some regex.match by building the pattern dynamically. The following code
I want to convert a string into a double and after doing some math
I have some html files that I want to convert to text. I have
I want some particular urls like springer.com to automatically convert to springer.com.proxy1.mycollege.edu. The second
I want to make a static class that would load some settings from XML
I want to access a model attribute in Javascript. I use the following code:
I'm converting a webapp from mysql to SQL Server. Now I want to convert
I want to convert a doc file to txt file, but some characters are

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.