Add generic print and println functions to FSharp.Core#19265
Open
bbatsov wants to merge 2 commits intodotnet:mainfrom
Open
Add generic print and println functions to FSharp.Core#19265bbatsov wants to merge 2 commits intodotnet:mainfrom
bbatsov wants to merge 2 commits intodotnet:mainfrom
Conversation
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.
Contributor
❗ Release notes required
|
vzarytovskii
reviewed
Feb 9, 2026
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) | ||
|
|
Member
There was a problem hiding this comment.
Should functions be inline?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
printandprintlnare generic ('T -> unit) rather thanstring -> unit, addressing the feedback from @dsyme that a generic print function would be a better use of the "good name":Both functions use the existing
stringoperator for conversion, which already:IFormattabletypes (consistent withprintfn,sprintf, etc.).ToString()for other types (F# types likeOption,List, etc. have good.ToString()overrides)Changes
printandprintlnsignatures with XML docs tofslib-extra-pervasives.fsifslib-extra-pervasives.fsPrintTests.fs) covering: string, int, float, bool, Option, None, list, newline behavior, and concatenationOpen questions
eprintf(n)andfprintf(n)? Do they generic counterparts as well?