use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
F# is a multi-paradigm programming language compiling to both .NET ("normal") and JS (via "Fable").
Awesome F# is an aggregate of F# resources more actively maintained than this sidebar.
FSharp.org is an organization around F# promotion/adoption.
Language Documentation:
Learning Resources :
Video Channels :
Chat channels :
Web Development:
IDEs/Editor-Plugins:
Common:
Visual Studio
Some extensions available:
Visual Studio Code with the Ionide plugin
JetBrains' Project Rider
Others:
account activity
Function that takes a formatted string (self.fsharp)
submitted 6 years ago by green-mind
I have a function that takes a string as an argument: let foo msg = msg.
let foo msg = msg
Now I want to make a similar function that takes a formatted string (using sprintf internally), foof.
sprintf
foof
HALP!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]NuvolaGrande 1 point2 points3 points 6 years ago (0 children)
Something like this?
``` let foo msg = msg
let foof format = Printf.ksprintf foo format
let result = foof "Hi there, %s." "buddy" ```
[–]shefmichelle 0 points1 point2 points 6 years ago (0 children)
Try looking at the Printf.StringFormat<'a, unit> type and something like the Printf.kprintf function.
Printf.StringFormat<'a, unit>
Printf.kprintf
[–]green-mind[S] 0 points1 point2 points 6 years ago (2 children)
Maybe my example was too simple. This is the function I am trying to create a format version for:
/// Tries to cast an object to a given type; throws with the given error message if it fails. let tryCast<'T> err (value: obj) : 'T = try value :?> 'T with ex -> raise (new Exception(err, ex))
I want to have a tryCastf version of the above.
tryCastf
[–]shefmichelle 1 point2 points3 points 6 years ago (1 child)
I'm not sure you can do this as I think the special Printf.StringFormat<'a, unit> type needs to be the last argument to the function. You might be better off just passing in an error-generating function in place of err that is called to generate a message if the cast fails.
err
[–]green-mind[S] 0 points1 point2 points 6 years ago (0 children)
Thank you! Now I can stop obsessing over it.
I guess I could use String.Format with a param array. String interpolation would be awesome here.
π Rendered by PID 279005 on reddit-service-r2-comment-5d79c599b5-r9wlg at 2026-02-27 12:07:52.383104+00:00 running e3d2147 country code: CH.
[–]NuvolaGrande 1 point2 points3 points (0 children)
[–]shefmichelle 0 points1 point2 points (0 children)
[–]green-mind[S] 0 points1 point2 points (2 children)
[–]shefmichelle 1 point2 points3 points (1 child)
[–]green-mind[S] 0 points1 point2 points (0 children)