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

  • Home
  • SEARCH
  • 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 7021453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:27:07+00:00 2026-05-27T23:27:07+00:00

I am learning RX, and trying to port some code in C# to F#.

  • 0

I am learning RX, and trying to port some code in C# to F#.
The following is C# example for using a timer:

Console.WriteLine("Current Time: " + DateTime.Now);
var source = Observable.Timer(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(1)).Timestamp();
using (source.Subscribe(x => Console.WriteLine("{0}: {1}", x.Value, x.Timestamp)))
      {
       Console.WriteLine("Press any key to unsubscribe");
       Console.ReadKey();
      }
Console.WriteLine("Press any key to exit");
Console.ReadKey();

The following is my code trying to do the same:

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


printfn "Current Time: %A" DateTime.Now

let source = Observable.Timer(TimeSpan.FromSeconds(5.0), TimeSpan.FromSeconds(1.0)).Timestamp()
source.Subscribe(fun x -> printfn "%A %A" x.Value x.Timestamp) |> ignore

But I got compiler errors:

Error 1 Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.

I don’t know how what type is for x.Value and x.Timestamp.
By the way, I also don’t know how to re-write using in C# here in F#.
Please show me the correct code for this.

  • 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-27T23:27:07+00:00Added an answer on May 27, 2026 at 11:27 pm

    Below is a “direct translation” into F# from C#:

    open System
    open System.Reactive
    open System.Reactive.Linq
    
    printfn "Current Time: %A" DateTime.Now
    let source = Observable.Timer(TimeSpan.FromSeconds(5.0), TimeSpan.FromSeconds      (1.0)).Timestamp()
    using (source.Subscribe(fun (x:Timestamped<int64>) -> printfn "%A %A" x.Value x.Timestamp))
        (fun _ ->
            printfn "Press any key to unsubscribe"
            Console.ReadKey() |> ignore
        )
    
    printfn "Press any key to stop"
    Console.ReadKey() |> ignore
    

    When running allow it to pass 5 seconds prior to seeing how 1 sec Timer events begin flowing in.

    ADDENDUM: Type of input argument in the lambda expression that, in turn, is the argument of Iobservable.Subscribe() is the type of values of IObservable that we call Subscribe() on, i.e the type of values constituing IObservable source.

    In turn, source represents result of Observable.Timer(DateTimeOffset, TimeSpan) method that returns an observable sequence that produces a value at due time and then after each period. This sequence has type IObservable<int64>.

    Timestamp() method, when being applied to IObservable<int64> yields IObservable<Timestamped<int64>>.

    So, eventually our source is IObservable of type Timestamped<int64>, which the code snippet above reflects as explicit type of argument x of the anonymous function within Subscribe().

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

Sidebar

Related Questions

I am learning QT and trying out some examples. I am trying to make
I'm just learning ruby and trying to understand the scope of code executed in
I'm a beginner to C programming. I'm trying to learning how to code a
I have just started learning Erlang and am trying out some Project Euler problems
Learning CasperJS Trying to understand why the following is not displaying my results in
I'm learning python and trying to write a code to sync two directories: one
Trying to learning some more PHP. Here is what I'm after. Essentially, I would
I'm learning Scala and trying to use javax.cache in Scala code and can't find
I'm learning jQuery by trying to understand other people's code. I ran into this:
I'm learning andEngine and trying to make a simple game based on some examples.

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.