Skip to content

Add generic print and println functions to FSharp.Core#19265

Open
bbatsov wants to merge 2 commits intodotnet:mainfrom
bbatsov:feature/print-println
Open

Add generic print and println functions to FSharp.Core#19265
bbatsov wants to merge 2 commits intodotnet:mainfrom
bbatsov:feature/print-println

Conversation

@bbatsov
Copy link
Contributor

@bbatsov bbatsov commented Feb 9, 2026

Summary

This is another take on RFC FS-1125, following up on the closed #13597. I guess that's mostly an attempt to see if anyone's interested in driving the old proposal to the finish line. For me those would definitely be handy functions to have, but obviously they are not something very important.

The key difference from the original PR is that print and println are generic ('T -> unit) rather than string -> unit, addressing the feedback from @dsyme that a generic print function would be a better use of the "good name":

let print (value: 'T) = Console.Out.Write(string value)
let println (value: 'T) = Console.Out.WriteLine(string value)

Both functions use the existing string operator for conversion, which already:

  • Uses InvariantCulture for IFormattable types (consistent with printfn, sprintf, etc.)
  • Passes strings through as-is
  • Falls back to .ToString() for other types (F# types like Option, List, etc. have good .ToString() overrides)

Changes

  • Added print and println signatures with XML docs to fslib-extra-pervasives.fsi
  • Added implementations in fslib-extra-pervasives.fs
  • Added unit tests (PrintTests.fs) covering: string, int, float, bool, Option, None, list, newline behavior, and concatenation
  • Updated all 4 surface area baselines

Open questions

  • What about eprintf(n) and fprintf(n)? Do they generic counterparts as well?

Add `print: 'T -> unit` and `println: 'T -> unit` to
ExtraTopLevelOperators. These use the existing `string` function for
conversion (InvariantCulture for IFormattable, .ToString() fallback)
and write to Console.Out.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2026

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/FSharp.Core docs/release-notes/.FSharp.Core/10.0.300.md

Comment on lines +280 to +287
[<CompiledName("PrintValue")>]
let print (value: 'T) =
Console.Out.Write(string value)

[<CompiledName("PrintValueLine")>]
let println (value: 'T) =
Console.Out.WriteLine(string value)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should functions be inline?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

2 participants