Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking - Docs - code examples for all members, functions and types in FSharp.Core #12124

Open
22 of 30 tasks
Tracked by #26813
dsyme opened this issue Sep 7, 2021 · 53 comments
Open
22 of 30 tasks
Tracked by #26813
Labels
Feature Improvement Theme-Simple-F# A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language. Tracking
Milestone

Comments

@dsyme
Copy link
Contributor

dsyme commented Sep 7, 2021

Related to https://twitter.com/dsymetweets/status/1435311963781861376

This is a tracking issue for adding code examples for all functions, members and types in FSharp.Core.

Modules and types to do:

@nhirschey
Copy link
Contributor

I could take a stab at the Array module examples over the next several weeks. Some initial attempts: https://github.com/nhirschey/visualfsharp/commit/c9327e18573488a0f34517f9fabc19864c9fc9b4

Quick questions:

  1. I see that one line examples are preferred. Should every example fit on one line? For beginners some things might be easier when split across multiple lines:
    • blit
      ///     let source = [| 1; 2; 3 |]
      ///     let sourceIndex = 0
      ///     let target = [| 0; 0; 0 |]
      ///     let targetIndex = 1
      ///     let count = 2
      ///     Array.blit source sourceIndex target targetIndex count 
      ///     target // evaluates to [| 0; 1; 2 |]
    • collect
      ///     let negative xs = xs |> Array.map (fun x -> -1 * x)
      ///     negative [| 1; 2 |] // evaluates to [-1; -2]
      ///     let ys = [| [| 1; 2 |]; [| 3; 4 |] |]
      ///     ys |> Array.collect negative // evaluates to [| -1; -2; -3; -4 |]
  2. For functions like Array.averageBy, is it useful to show that it is equivalent to Array.map |> Array.average?
[| 1.0; 2.0 |] |> Array.averageBy (fun x -> -1.0 * x) // evaluates to -1.5
// this is equivalent to
[| 1.0; 2.0 |] |> Array.map (fun x -> -1.0 * x) |> Array.average // evaluates to -1.5 
  1. Should there be a column-width limit for examples? Wide examples might be harder to read in tooltips. Here's 2 versions of the same example using different numbers of columns:
    image

@baronfel
Copy link
Member

baronfel commented Sep 7, 2021

One thing I would really encourage people to do is add a lang=fsharp attribute to your code example XML tags. It's not strictly speaking to-spec (IMO the .Net XML Documentation spec is fairly lacking here), but it is used in several places (like FSharp.Formatting and FsAutoComplete) to provide users with language-aware syntax highlighting. Stealing from @nhirschey's examples a bit:

  • blit:
///<example>
/// The following sample shows how to copy the first two elements of an array to the 
/// second and third positions of another array:
///
///<code lang="fsharp">
///     let source = [| 1; 2; 3 |]
///     let sourceIndex = 0
///     let target = [| 0; 0; 0 |]
///     let targetIndex = 1
///     let count = 2
///     Array.blit source sourceIndex target targetIndex count 
///     target // evaluates to [| 0; 1; 2 |]
///</code>
///</example>

@dsyme
Copy link
Contributor Author

dsyme commented Sep 7, 2021

@baronfel thank you, yes! Is it used consistently in Fsharp.core today? If not please submit a pr to do that?

We should also mention that here

https://github.com/fsharp/fslang-design/blob/main/tooling/FST-1031-xmldoc-extensions.md

@dsyme
Copy link
Contributor Author

dsyme commented Sep 7, 2021

@nhirschey thank you so much for kicking this off - the examples for Array can be reused for list and seq of course

  1. multiline samples are definitely needed. Separate them out and take as much space as you need. For complex functions more discursive text may be needed.

  2. Regarding equivalences - I think not.

  3. Yes but I'm not sure what it should be. I expect 80. We will move to one-function-per-page docs for fsharp.core fsdocs eventually when much more space will be available so don't restrict up 60

@JYCabello
Copy link
Contributor

Can I take Seq?

@MecuSorin
Copy link

I will use those as an exercise for my son in his attempt to learn F#. I am very serious. What he is not able/experienced enough, I will do them myself.

@dsyme
Copy link
Contributor Author

dsyme commented Sep 8, 2021

@JYCabello The same examples should generally be used for Seq, Array, List (with minor adjustment) - so since @nhirschey is starting at the top of Array I recommend you start at the bottom of Seq, alphabetically?

@JYCabello
Copy link
Contributor

I will do. Starting tomorrow.

@MecuStefan
Copy link
Contributor

String is done, working on the List at the moment

@JYCabello
Copy link
Contributor

Got to ask: The examples go between the docs for the params and the return type for any particular reason?

@dsyme
Copy link
Contributor Author

dsyme commented Sep 9, 2021

Got to ask: The examples go between the docs for the params and the return type for any particular reason?

No reason - they should be come after I agree. Please feel free to submit a PR doing a re-ordering

@JYCabello
Copy link
Contributor

Great, will do after that. I just noticed that you specifically mentioned to start on the bottom and I started on the top. Sorry about that. I'll make a PR in a bit to have some progress in and to get some feedback.

@MaxWilson
Copy link
Contributor

MaxWilson commented Sep 11, 2021

I will take Set and Map.

@JustinWick
Copy link
Contributor

JustinWick commented Sep 12, 2021

I'm going to give FSharp.Control.Async a stab, should be fun. Probably won't be able to get to the extensions, though.

The examples for these modules must necessarily be nontrivial given the differences in timing behavior exhibited by some of the Async functions. I would like to have my documentation peer-reviewed while in progress rather than having it rejected outright as too obtuse, is there an established way to do this? Maybe some kind of WIP PR?

@dsyme
Copy link
Contributor Author

dsyme commented Sep 13, 2021

Thank you Max! Thank you Justin!

@JustinWick
Copy link
Contributor

Alright, I'm up to 13 examples for Async, I'm expecting to create a PR by Thursday. Do I just file the PR and then have peer review there?

@dsyme
Copy link
Contributor Author

dsyme commented Sep 13, 2021

Alright, I'm up to 13 examples for Async, I'm expecting to create a PR by Thursday. Do I just file the PR and then have peer review there?

Fantastic! Yes, that's right

@sgoguen
Copy link
Contributor

sgoguen commented Sep 14, 2021

I will take FSharp.Core.Operators

@dsyme
Copy link
Contributor Author

dsyme commented Sep 14, 2021

@sgoguen Great!

@dsyme
Copy link
Contributor Author

dsyme commented Sep 16, 2021

#12161 contains work to add <example-tbd> to all the places we need examples, except in Operators.

@JustinWick There may be a few minor merge conflicts if you've done more work, e.g. in Async - they should be easy to resolve - perhaps before merging first reduce the indenting in async.fsi to match the change in that PR, then the conflicts will be easy to resolve.

@dsyme dsyme added Theme-Simple-F# A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language. Feature Improvement labels Sep 16, 2021
@JustinWick
Copy link
Contributor

#12161 contains work to add <example-tbd> to all the places we need examples, except in Operators.

@JustinWick There may be a few minor merge conflicts if you've done more work, e.g. in Async - they should be easy to resolve - perhaps before merging first reduce the indenting in async.fsi to match the change in that PR, then the conflicts will be easy to resolve.

I am just about done with examples but I forgot to transfer them to my laptop before leaving for a trip. I'll be back Tuesday and can merge them into the PR Wednesday, is that going to cause any issues?

@dsyme
Copy link
Contributor Author

dsyme commented Oct 12, 2021

After #12233 the score is

  • 860 completed examples
  • 381 undocumented <example-tbd>

@markpattison
Copy link
Contributor

markpattison commented Oct 16, 2021

I should be able to do ValueOption quickly.

Noticed in the Option examples (I will fix) that the following actually throws FS0030:

(None, None) ||> Option.orElse // evaluates to None

Same for a few other cases.

@JYCabello
Copy link
Contributor

I was planning to do value option this week precisely due to that, but my days became a comedy flick. Feel free to take over, should be mostly copy pasta from option.

@dsyme
Copy link
Contributor Author

dsyme commented Oct 17, 2021

Thank for doing ValueOption Mark!

The main ones remaining are Async, FSharpType, FSharpValue, plus some more quotation examples, also finishing FSharp.Core.Operators

@JustinWick how are the async samples coming along? If you want to PR what you can have we can help you iterate?

@dsyme dsyme added the Impact-High (Internal MS Team use only) Describes an issue with extreme impact on existing code. label Nov 4, 2021
@dsyme
Copy link
Contributor Author

dsyme commented Nov 19, 2021

@JustinWick any progress on the async samples? It would be great to get this whole work item closed out, we've made such good progress in F# 6

@JustinWick
Copy link
Contributor

JustinWick commented Nov 20, 2021 via email

@dsyme
Copy link
Contributor Author

dsyme commented Nov 20, 2021

@JustinWick Great! Anything you have would be good, so we can avoid overlap

@JustinWick
Copy link
Contributor

JustinWick commented Dec 1, 2021

@dsyme: Thank you very much for your patience, I bit off a bit much for my first contribution. Still this was a great way to learn the Async module--at my day job I have to use the Ply library for performance reasons, but Async makes a lot of things neater when that's not an issue.

I've got all my ducks in a row here and filed my PR #12477. It's not complete, as there were a few functions that were not there when I started on F# 5, are legacy functions, or for which I wasn't immediately able to think of an example. Still, I've added 22 examples, which should be a solid start.

@leolorenzoluis
Copy link
Contributor

@dsyme Please review my PR #12644 when you get a chance :)

@dsyme
Copy link
Contributor Author

dsyme commented Jan 31, 2022

Great to see more progress on this!

@dsyme
Copy link
Contributor Author

dsyme commented Feb 8, 2022

Great to see Observable be completed! Not that many more to go :)

@KevinRansom KevinRansom removed the Impact-High (Internal MS Team use only) Describes an issue with extreme impact on existing code. label Mar 9, 2022
@vzarytovskii vzarytovskii moved this to Not Planned in F# Compiler and Tooling Jun 17, 2022
@vzarytovskii vzarytovskii added this to the Backlog milestone Oct 19, 2022
@vzarytovskii vzarytovskii changed the title Tracking issues for code examples for all members, functions and types in FSharp.Core Tracking - Docs - code examples for all members, functions and types in FSharp.Core Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Improvement Theme-Simple-F# A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language. Tracking
Projects
Status: New
Development

No branches or pull requests