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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:10:58+00:00 2026-06-02T21:10:58+00:00

Since I do research with F# (in particular, using F# interactive), I’d like to

  • 0

Since I do research with F# (in particular, using F# interactive), I’d like to have switchable “print-when-in-debug” function.

I can do

let dprintfn = printfn

F# interactive says

val dprintfn : (Printf.TextWriterFormat<'a> -> 'a)

and I can use

dprintfn "myval1 = %d, other val = %A" a b

whenever I want in my scripts.

Now I’d like to define dprintfn differently, so that it would ignore all its arguments yet being syntax-compatible with printfn. How?


The closest (yet non-working) variant I have in mind is:

let dprintfn (arg: (Printf.TextWriterFormat<'a> -> 'a)) = ()

but it the following doesn’t compile then dprintfn "%A" "Hello", resulting in error FS0003: This value is not a function and cannot be applied.

P.S. I currently use an alias for Debug.WriteLine(...) as work-around, but the question is still interesting for understading F#’s type system.

  • 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-06-02T21:10:59+00:00Added an answer on June 2, 2026 at 9:10 pm

    You can use the kprintf function, which formats a string using the standard syntax, but then calls a (lambda) function you specify to print the formatted string.

    For example, the following prints the string if debug is set and otherwise does nothing:

    let myprintf fmt = Printf.kprintf (fun str -> 
      // Output the formatted string if 'debug', otherwise do nothing
      if debug then printfn "%s" str) fmt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a many-to-many relationship between People and Departments since one person can be
from my research it looks like there are basically 3 options. 1: Using COM
Since now I have only used plugin for editing and the way I use
Since I have no errors I don't know if this is the right place
Since each thread has its own stack, its private data can be put on
Since Intellij does not yet support the Play-Scala-Template-Engine I was thinking about using plain
I have been using Windows 7 for a while but have not had to
I have an application that has been running fine since its launch over a
I have been doing research on HTML canvas libraries and I came across this
I understand from my research that IE8 does annoying things like forcing itself into

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.