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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:29:08+00:00 2026-05-11T21:29:08+00:00

I was playing around with F# (Visual Studio 2010 beta 1), and I wrote

  • 0

I was playing around with F# (Visual Studio 2010 beta 1), and I wrote a little console script that asked the user to input 2 numbers and an operator and then executed it.
It works fine, apart from a tiny, but annoying thing: sometimes my printfn instructions are ignored. I placed breakpoints in the code to see that’s indeed the case.

The code snippet:

let convert (source : string) =
    try System.Int32.Parse(source)
    with :? System.FormatException ->
        printfn "'%s' is not a number!" source;
        waitForExitKey();
        exit 1

let read =
    printfn "Please enter a number.";
    System.Console.ReadLine

let num1 : int = read() |> convert // the printfn in the read function is run...
let num2 : int = read() |> convert // ... but here is ignored

This is not the complete source of course, but I think that’ll be enough. If you need the complete source just let me know.

So my question is pretty simple: what causes this issue with printfn? Am I doing something wrong?

Thanks in advance,
ShdNx

  • 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-11T21:29:08+00:00Added an answer on May 11, 2026 at 9:29 pm

    This page has a partial explanation of what’s going on, but the short and sweet version is that F# will execute any value on declaration if it doesn’t take parameters.

    let read =
        printfn "Please enter a number."
        System.Console.ReadLine
    

    Since read doesn’t take any parameters, its executed immediately on declaration and binds the return value of the function to the identifier read.

    Incidentally, your return value happens to be a function with the type (unit -> string). This results because F# automatically curries functions if they aren’t passed all of their parameters. ReadLine expects one unit parameter, but since it isn’t passed on, you actually bind read to the ReadLine function itself.

    The solution is as follows:

    let read() = // read takes one unit parameter
        printfn "Please enter a number."
        System.Console.ReadLine() // pass paramter to ReadLine method
    

    Since read takes one parameter, its re-evaluated each time its called. Additionally, we’re passing a parameter to ReadLine, otherwise we’ll just return the ReadLine function as a value.

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

Sidebar

Related Questions

I have been playing around with Visual Studio 2010 over the past few days
I am currently playing around with VB.Net using Visual Studio 2010 (.Net 4.0) and
I'm using Visual Studio 2010, and have the tangibleT4EditorPlusModellingTools installed. I'm just playing around
I just upgraded to Visual Studio 2010, and I am playing around with the
I'm just playing around with a grub-bootable C++ kernel in visual studio 2010. I've
I've noticed that Visual Studio 2008 is placing square brackets around column names in
Whilst playing around with resources in my visual studio 10 project, I came across
I am playing around with a small MFC-wizard-generated application, in Visual C++ 2010, and
I was just playing around with exceptions in the visual studio and with the
While playing around with regexps in Scala I wrote something like this: scala> val

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.