From 0cc05f9d23569c20352c1a29208a5dd3ab0e51f1 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Wed, 8 Sep 2021 16:24:45 +0300 Subject: [PATCH 01/14] Sorted the string.fsi entries and added examples to each one --- src/fsharp/FSharp.Core/string.fsi | 232 ++++++++++++++++++++++-------- 1 file changed, 172 insertions(+), 60 deletions(-) diff --git a/src/fsharp/FSharp.Core/string.fsi b/src/fsharp/FSharp.Core/string.fsi index cca1054f58a..62d8c86296b 100644 --- a/src/fsharp/FSharp.Core/string.fsi +++ b/src/fsharp/FSharp.Core/string.fsi @@ -18,6 +18,29 @@ namespace Microsoft.FSharp.Core [] module String = + /// Builds a new string whose characters are the results of applying the function mapping + /// to each of the characters of the input string and concatenating the resulting + /// strings. + /// + /// The function to produce a string from each character of the input string. + /// The input string. + /// + /// The concatenated string. + /// + /// The following samples shows how to interspace spaces in a text + /// + /// String.collect (sprintf "%c ") "Stefan says: Hi!" // evaluates "S t e f a n s a y s : H i ! " + /// + /// + /// + /// How to show the ASCII representation of a very secret text: + /// + /// String.collect (fun chr -> int chr |> sprintf "%d ") "Secret" // evaluates "83 101 99 114 101 116 " + /// + /// + [] + val collect: mapping:(char -> string) -> str:string -> string + /// Returns a new string made by concatenating the given strings /// with separator sep, that is a1 + sep + ... + sep + aN. /// The separator string to be inserted between the strings @@ -27,54 +50,32 @@ namespace Microsoft.FSharp.Core /// A new string consisting of the concatenated strings separated by /// the separation string. /// Thrown when strings is null. + /// + /// + /// + /// String.concat " " ["Stefan"; "says:"; "Hello"; "there!"] // evaluates "Stefan says: Hello there!" + /// [0..9] |> List.map string |> String.concat "" // evaluates "0123456789" + /// String.concat "!" ["No exclamation point here"] // evaluates "No exclamation point here" + /// + /// [] val concat: sep:string -> strings: seq -> string - /// Applies the function action to each character in the string. - /// - /// The function to be applied to each character of the string. - /// The input string. - [] - val iter: action:(char -> unit) -> str:string -> unit - - /// Applies the function action to the index of each character in the string and the - /// character itself. - /// - /// The function to apply to each character and index of the string. - /// The input string. - [] - val iteri: action:(int -> char -> unit) -> str:string -> unit - - /// Builds a new string whose characters are the results of applying the function mapping - /// to each of the characters of the input string. - /// - /// The function to apply to the characters of the string. - /// The input string. - /// - /// The resulting string. - [] - val map: mapping:(char -> char) -> str:string -> string - - /// Builds a new string whose characters are the results of applying the function mapping - /// to each character and index of the input string. - /// - /// The function to apply to each character and index of the string. - /// The input string. - /// - /// The resulting string. - [] - val mapi: mapping:(int -> char -> char) -> str:string -> string - - /// Builds a new string whose characters are the results of applying the function mapping - /// to each of the characters of the input string and concatenating the resulting - /// strings. + /// Tests if any character of the string satisfies the given predicate. /// - /// The function to produce a string from each character of the input string. + /// The function to test each character of the string. /// The input string. /// - /// The concatenated string. - [] - val collect: mapping:(char -> string) -> str:string -> string + /// True if any character returns true for the predicate and false otherwise. + /// + /// Looking for uppercase characters + /// + /// String.exists System.Char.IsUpper "Yoda" // evaluates true + /// String.exists System.Char.IsUpper "nope" // evaluates false + /// + /// + [] + val exists: predicate:(char -> bool) -> str:string -> bool /// Builds a new string containing only the characters of the input string /// for which the given predicate returns "true". @@ -85,9 +86,32 @@ namespace Microsoft.FSharp.Core /// The input string. /// /// The resulting string. + /// + /// Filtering out just alphanumeric characters or just digits + /// + /// String.filter System.Uri.IsHexDigit "0 1 2 3 4 5 6 7 8 9 a A m M" // evaluates "123456789aA" + /// String.filter System.Char.IsDigit "hello" // evaluates "" + /// + /// [] val filter: predicate:(char -> bool) -> str:string -> string + /// Tests if all characters in the string satisfy the given predicate. + /// + /// The function to test each character of the string. + /// The input string. + /// + /// True if all characters return true for the predicate and false otherwise. + /// + /// Looking for lowercase characters + /// + /// String.forall System.Char.IsLower "all are lower" // evaluates false + /// String.forall System.Char.IsLower "allarelower" // evaluates true + /// + /// + [] + val forall: predicate:(char -> bool) -> str:string -> bool + /// Builds a new string whose characters are the results of applying the function mapping /// to each index from 0 to count-1 and concatenating the resulting /// strings. @@ -98,26 +122,115 @@ namespace Microsoft.FSharp.Core /// /// The constructed string. /// Thrown when count is negative. + /// + /// Enumerate digits ASCII codes + /// + /// String.init 10 (fun i -> int '0' + i |> sprintf "%d ") // evaluates "48 49 50 51 52 53 54 55 56 57 " + /// + /// [] val init: count:int -> initializer:(int -> string) -> string - /// Tests if all characters in the string satisfy the given predicate. + /// Applies the function action to each character in the string. /// - /// The function to test each character of the string. + /// The function to be applied to each character of the string. /// The input string. + /// + /// + /// + /// String.iter (fun c -> printfn "%c %d" c (int c)) "Hello" + /// // evaluates unit + /// // prints: + /// H 72 + /// e 101 + /// l 108 + /// l 108 + /// o 111 + /// + /// + [] + val iter: action:(char -> unit) -> str:string -> unit + + /// Applies the function action to the index of each character in the string and the + /// character itself. /// - /// True if all characters return true for the predicate and false otherwise. - [] - val forall: predicate:(char -> bool) -> str:string -> bool + /// The function to apply to each character and index of the string. + /// The input string. + /// + /// + /// + /// String.length null // evaluates 0 + /// String.length "" // evaluates 0 + /// String.length "123" // evaluates 3 + /// + /// + /// + /// + /// + /// String.iteri (fun i c -> printfn "%d. %c %d" (i + 1) c (int c)) "Hello" + /// // evaluates unit + /// // prints: + /// 1. H 72 + /// 2. e 101 + /// 3. l 108 + /// 4. l 108 + /// 5. o 111 + /// + /// + [] + val iteri: action:(int -> char -> unit) -> str:string -> unit - /// Tests if any character of the string satisfies the given predicate. + /// Returns the length of the string. /// - /// The function to test each character of the string. /// The input string. /// - /// True if any character returns true for the predicate and false otherwise. - [] - val exists: predicate:(char -> bool) -> str:string -> bool + /// The number of characters in the string. + /// + /// + /// + /// String.length null // evaluates 0 + /// String.length "" // evaluates 0 + /// String.length "123" // evaluates 3 + /// + /// + [] + val length: str:string -> int + + /// Builds a new string whose characters are the results of applying the function mapping + /// to each of the characters of the input string. + /// + /// The function to apply to the characters of the string. + /// The input string. + /// + /// The resulting string. + /// + /// Changing case to upper for all characters in the input string + /// + /// String.map System.Char.ToUpper "Hello there!" // evaluates "HELLO THERE!" + /// + /// + [] + val map: mapping:(char -> char) -> str:string -> string + + /// Builds a new string whose characters are the results of applying the function mapping + /// to each character and index of the input string. + /// + /// The function to apply to each character and index of the string. + /// The input string. + /// + /// The resulting string. + /// + /// Alternating case for all characters in the input string + /// + /// let alternateCase indx chr = + /// if 0 = indx % 2 + /// then System.Char.ToUpper chr + /// else System.Char.ToLower chr + /// String.mapi alternateCase "Hello there!" // evaluates "HeLlO ThErE!" + /// + /// + [] + val mapi: mapping:(int -> char -> char) -> str:string -> string /// Returns a string by concatenating count instances of str. /// @@ -126,14 +239,13 @@ namespace Microsoft.FSharp.Core /// /// The concatenated string. /// Thrown when count is negative. + /// + /// + /// + /// String.replicate 3 "Do it! " // evaluates "Do it! Do it! Do it! " + /// + /// [] val replicate: count:int -> str: string -> string - - /// Returns the length of the string. - /// - /// The input string. - /// - /// The number of characters in the string. - [] - val length: str:string -> int + From 918673f8b78ed122f8d0ca3e1792ff79bbf16f97 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Wed, 8 Sep 2021 18:08:32 +0300 Subject: [PATCH 02/14] Applying suggestions to the String examples --- src/fsharp/FSharp.Core/string.fsi | 99 +++++++++++++++++++------------ 1 file changed, 60 insertions(+), 39 deletions(-) diff --git a/src/fsharp/FSharp.Core/string.fsi b/src/fsharp/FSharp.Core/string.fsi index 62d8c86296b..6cd6683da9f 100644 --- a/src/fsharp/FSharp.Core/string.fsi +++ b/src/fsharp/FSharp.Core/string.fsi @@ -27,15 +27,16 @@ namespace Microsoft.FSharp.Core /// /// The concatenated string. /// - /// The following samples shows how to interspace spaces in a text + /// The following samples shows how to interspace spaces in a text /// - /// String.collect (sprintf "%c ") "Stefan says: Hi!" // evaluates "S t e f a n s a y s : H i ! " + /// let input = "Stefan says: Hi!" + /// input |> String.collect (sprintf "%c ") // evaluates "S t e f a n s a y s : H i ! " /// /// /// - /// How to show the ASCII representation of a very secret text: + /// How to show the ASCII representation of a very secret text /// - /// String.collect (fun chr -> int chr |> sprintf "%d ") "Secret" // evaluates "83 101 99 114 101 116 " + /// "Secret" |> String.collect (fun chr -> int chr |> sprintf "%d ") // evaluates "83 101 99 114 101 116 " /// /// [] @@ -51,11 +52,16 @@ namespace Microsoft.FSharp.Core /// the separation string. /// Thrown when strings is null. /// - /// + /// /// - /// String.concat " " ["Stefan"; "says:"; "Hello"; "there!"] // evaluates "Stefan says: Hello there!" - /// [0..9] |> List.map string |> String.concat "" // evaluates "0123456789" - /// String.concat "!" ["No exclamation point here"] // evaluates "No exclamation point here" + /// let input1 = ["Stefan"; "says:"; "Hello"; "there!"] + /// input1 |> String.concat " " // evaluates "Stefan says: Hello there!" + /// + /// let input2 = [0..9] |> List.map string + /// input2 |> String.concat "" // evaluates "0123456789" + /// + /// let input3 = ["No exclamation point here"] + /// input3 |> String.concat "!" // evaluates "No exclamation point here" /// /// [] @@ -68,10 +74,13 @@ namespace Microsoft.FSharp.Core /// /// True if any character returns true for the predicate and false otherwise. /// - /// Looking for uppercase characters + /// Looking for uppercase characters /// - /// String.exists System.Char.IsUpper "Yoda" // evaluates true - /// String.exists System.Char.IsUpper "nope" // evaluates false + /// open System + /// + /// "Yoda" |> String.exists Char.IsUpper // evaluates true + /// + /// "nope" |> String.exists Char.IsUpper // evaluates false /// /// [] @@ -87,10 +96,19 @@ namespace Microsoft.FSharp.Core /// /// The resulting string. /// - /// Filtering out just alphanumeric characters or just digits + /// Filtering out just alphanumeric characters + /// + /// open System + /// + /// let input = "0 1 2 3 4 5 6 7 8 9 a A m M" + /// input |> String.filter Uri.IsHexDigit // evaluates "123456789aA" + /// + /// + /// Filtering out just digits /// - /// String.filter System.Uri.IsHexDigit "0 1 2 3 4 5 6 7 8 9 a A m M" // evaluates "123456789aA" - /// String.filter System.Char.IsDigit "hello" // evaluates "" + /// open System + /// + /// "hello" |> String.filter Char.IsDigit // evaluates "" /// /// [] @@ -103,10 +121,13 @@ namespace Microsoft.FSharp.Core /// /// True if all characters return true for the predicate and false otherwise. /// - /// Looking for lowercase characters + /// Looking for lowercase characters /// - /// String.forall System.Char.IsLower "all are lower" // evaluates false - /// String.forall System.Char.IsLower "allarelower" // evaluates true + /// open System + /// + /// "all are lower" |> String.forall Char.IsLower // evaluates false + /// + /// "allarelower" |> String.forall Char.IsLower // evaluates true /// /// [] @@ -123,7 +144,7 @@ namespace Microsoft.FSharp.Core /// The constructed string. /// Thrown when count is negative. /// - /// Enumerate digits ASCII codes + /// Enumerate digits ASCII codes /// /// String.init 10 (fun i -> int '0' + i |> sprintf "%d ") // evaluates "48 49 50 51 52 53 54 55 56 57 " /// @@ -136,9 +157,10 @@ namespace Microsoft.FSharp.Core /// The function to be applied to each character of the string. /// The input string. /// - /// + /// Printing the ASCII code for each characater in the string /// - /// String.iter (fun c -> printfn "%c %d" c (int c)) "Hello" + /// let input = "Hello" + /// input |> String.iter (fun c -> printfn "%c %d" c (int c)) /// // evaluates unit /// // prints: /// H 72 @@ -157,17 +179,11 @@ namespace Microsoft.FSharp.Core /// The function to apply to each character and index of the string. /// The input string. /// - /// + /// Numbering the characters and printing the associated ASCII code + /// for each characater in the input string /// - /// String.length null // evaluates 0 - /// String.length "" // evaluates 0 - /// String.length "123" // evaluates 3 - /// - /// - /// - /// - /// - /// String.iteri (fun i c -> printfn "%d. %c %d" (i + 1) c (int c)) "Hello" + /// let input = "Hello" + /// input |> String.iteri (fun i c -> printfn "%d. %c %d" (i + 1) c (int c)) /// // evaluates unit /// // prints: /// 1. H 72 @@ -186,7 +202,7 @@ namespace Microsoft.FSharp.Core /// /// The number of characters in the string. /// - /// + /// Getting the length of different strings /// /// String.length null // evaluates 0 /// String.length "" // evaluates 0 @@ -204,9 +220,11 @@ namespace Microsoft.FSharp.Core /// /// The resulting string. /// - /// Changing case to upper for all characters in the input string + /// Changing case to upper for all characters in the input string /// - /// String.map System.Char.ToUpper "Hello there!" // evaluates "HELLO THERE!" + /// open System + /// let input = "Hello there!" + /// input |> String.map Char.ToUpper // evaluates "HELLO THERE!" /// /// [] @@ -220,13 +238,16 @@ namespace Microsoft.FSharp.Core /// /// The resulting string. /// - /// Alternating case for all characters in the input string + /// Alternating case for all characters in the input string /// + /// open System + /// /// let alternateCase indx chr = /// if 0 = indx % 2 - /// then System.Char.ToUpper chr - /// else System.Char.ToLower chr - /// String.mapi alternateCase "Hello there!" // evaluates "HeLlO ThErE!" + /// then Char.ToUpper chr + /// else Char.ToLower chr + /// let input = "Hello there!" + /// input |> String.mapi alternateCase // evaluates "HeLlO ThErE!" /// /// [] @@ -240,9 +261,9 @@ namespace Microsoft.FSharp.Core /// The concatenated string. /// Thrown when count is negative. /// - /// + /// /// - /// String.replicate 3 "Do it! " // evaluates "Do it! Do it! Do it! " + /// "Do it!" |> String.replicate 3 // evaluates "Do it!Do it!Do it!" /// /// [] From 1f4e7900629f45fc3858631d2192e9dd2e237cb9 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Wed, 8 Sep 2021 19:14:00 +0300 Subject: [PATCH 03/14] Following the suggestion that is more clear. --- src/fsharp/FSharp.Core/string.fsi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/fsharp/FSharp.Core/string.fsi b/src/fsharp/FSharp.Core/string.fsi index 6cd6683da9f..73174bc6bbd 100644 --- a/src/fsharp/FSharp.Core/string.fsi +++ b/src/fsharp/FSharp.Core/string.fsi @@ -58,10 +58,11 @@ namespace Microsoft.FSharp.Core /// input1 |> String.concat " " // evaluates "Stefan says: Hello there!" /// /// let input2 = [0..9] |> List.map string - /// input2 |> String.concat "" // evaluates "0123456789" + /// input2 |> String.concat "" // evaluates "0123456789" + /// input2 |> String.concat ", " // evaluates "0, 1, 2, 3, 4, 5, 6, 7, 8, 9" /// - /// let input3 = ["No exclamation point here"] - /// input3 |> String.concat "!" // evaluates "No exclamation point here" + /// let input3 = ["No comma"] + /// input3 |> String.concat "," // evaluates "No comma" /// /// [] From 36935c9c88d5da0e7d92a03785cc872e65fae258 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Wed, 8 Sep 2021 16:24:45 +0300 Subject: [PATCH 04/14] Sorted the string.fsi entries and added examples to each one --- src/fsharp/FSharp.Core/string.fsi | 232 ++++++++++++++++++++++-------- 1 file changed, 172 insertions(+), 60 deletions(-) diff --git a/src/fsharp/FSharp.Core/string.fsi b/src/fsharp/FSharp.Core/string.fsi index cca1054f58a..62d8c86296b 100644 --- a/src/fsharp/FSharp.Core/string.fsi +++ b/src/fsharp/FSharp.Core/string.fsi @@ -18,6 +18,29 @@ namespace Microsoft.FSharp.Core [] module String = + /// Builds a new string whose characters are the results of applying the function mapping + /// to each of the characters of the input string and concatenating the resulting + /// strings. + /// + /// The function to produce a string from each character of the input string. + /// The input string. + /// + /// The concatenated string. + /// + /// The following samples shows how to interspace spaces in a text + /// + /// String.collect (sprintf "%c ") "Stefan says: Hi!" // evaluates "S t e f a n s a y s : H i ! " + /// + /// + /// + /// How to show the ASCII representation of a very secret text: + /// + /// String.collect (fun chr -> int chr |> sprintf "%d ") "Secret" // evaluates "83 101 99 114 101 116 " + /// + /// + [] + val collect: mapping:(char -> string) -> str:string -> string + /// Returns a new string made by concatenating the given strings /// with separator sep, that is a1 + sep + ... + sep + aN. /// The separator string to be inserted between the strings @@ -27,54 +50,32 @@ namespace Microsoft.FSharp.Core /// A new string consisting of the concatenated strings separated by /// the separation string. /// Thrown when strings is null. + /// + /// + /// + /// String.concat " " ["Stefan"; "says:"; "Hello"; "there!"] // evaluates "Stefan says: Hello there!" + /// [0..9] |> List.map string |> String.concat "" // evaluates "0123456789" + /// String.concat "!" ["No exclamation point here"] // evaluates "No exclamation point here" + /// + /// [] val concat: sep:string -> strings: seq -> string - /// Applies the function action to each character in the string. - /// - /// The function to be applied to each character of the string. - /// The input string. - [] - val iter: action:(char -> unit) -> str:string -> unit - - /// Applies the function action to the index of each character in the string and the - /// character itself. - /// - /// The function to apply to each character and index of the string. - /// The input string. - [] - val iteri: action:(int -> char -> unit) -> str:string -> unit - - /// Builds a new string whose characters are the results of applying the function mapping - /// to each of the characters of the input string. - /// - /// The function to apply to the characters of the string. - /// The input string. - /// - /// The resulting string. - [] - val map: mapping:(char -> char) -> str:string -> string - - /// Builds a new string whose characters are the results of applying the function mapping - /// to each character and index of the input string. - /// - /// The function to apply to each character and index of the string. - /// The input string. - /// - /// The resulting string. - [] - val mapi: mapping:(int -> char -> char) -> str:string -> string - - /// Builds a new string whose characters are the results of applying the function mapping - /// to each of the characters of the input string and concatenating the resulting - /// strings. + /// Tests if any character of the string satisfies the given predicate. /// - /// The function to produce a string from each character of the input string. + /// The function to test each character of the string. /// The input string. /// - /// The concatenated string. - [] - val collect: mapping:(char -> string) -> str:string -> string + /// True if any character returns true for the predicate and false otherwise. + /// + /// Looking for uppercase characters + /// + /// String.exists System.Char.IsUpper "Yoda" // evaluates true + /// String.exists System.Char.IsUpper "nope" // evaluates false + /// + /// + [] + val exists: predicate:(char -> bool) -> str:string -> bool /// Builds a new string containing only the characters of the input string /// for which the given predicate returns "true". @@ -85,9 +86,32 @@ namespace Microsoft.FSharp.Core /// The input string. /// /// The resulting string. + /// + /// Filtering out just alphanumeric characters or just digits + /// + /// String.filter System.Uri.IsHexDigit "0 1 2 3 4 5 6 7 8 9 a A m M" // evaluates "123456789aA" + /// String.filter System.Char.IsDigit "hello" // evaluates "" + /// + /// [] val filter: predicate:(char -> bool) -> str:string -> string + /// Tests if all characters in the string satisfy the given predicate. + /// + /// The function to test each character of the string. + /// The input string. + /// + /// True if all characters return true for the predicate and false otherwise. + /// + /// Looking for lowercase characters + /// + /// String.forall System.Char.IsLower "all are lower" // evaluates false + /// String.forall System.Char.IsLower "allarelower" // evaluates true + /// + /// + [] + val forall: predicate:(char -> bool) -> str:string -> bool + /// Builds a new string whose characters are the results of applying the function mapping /// to each index from 0 to count-1 and concatenating the resulting /// strings. @@ -98,26 +122,115 @@ namespace Microsoft.FSharp.Core /// /// The constructed string. /// Thrown when count is negative. + /// + /// Enumerate digits ASCII codes + /// + /// String.init 10 (fun i -> int '0' + i |> sprintf "%d ") // evaluates "48 49 50 51 52 53 54 55 56 57 " + /// + /// [] val init: count:int -> initializer:(int -> string) -> string - /// Tests if all characters in the string satisfy the given predicate. + /// Applies the function action to each character in the string. /// - /// The function to test each character of the string. + /// The function to be applied to each character of the string. /// The input string. + /// + /// + /// + /// String.iter (fun c -> printfn "%c %d" c (int c)) "Hello" + /// // evaluates unit + /// // prints: + /// H 72 + /// e 101 + /// l 108 + /// l 108 + /// o 111 + /// + /// + [] + val iter: action:(char -> unit) -> str:string -> unit + + /// Applies the function action to the index of each character in the string and the + /// character itself. /// - /// True if all characters return true for the predicate and false otherwise. - [] - val forall: predicate:(char -> bool) -> str:string -> bool + /// The function to apply to each character and index of the string. + /// The input string. + /// + /// + /// + /// String.length null // evaluates 0 + /// String.length "" // evaluates 0 + /// String.length "123" // evaluates 3 + /// + /// + /// + /// + /// + /// String.iteri (fun i c -> printfn "%d. %c %d" (i + 1) c (int c)) "Hello" + /// // evaluates unit + /// // prints: + /// 1. H 72 + /// 2. e 101 + /// 3. l 108 + /// 4. l 108 + /// 5. o 111 + /// + /// + [] + val iteri: action:(int -> char -> unit) -> str:string -> unit - /// Tests if any character of the string satisfies the given predicate. + /// Returns the length of the string. /// - /// The function to test each character of the string. /// The input string. /// - /// True if any character returns true for the predicate and false otherwise. - [] - val exists: predicate:(char -> bool) -> str:string -> bool + /// The number of characters in the string. + /// + /// + /// + /// String.length null // evaluates 0 + /// String.length "" // evaluates 0 + /// String.length "123" // evaluates 3 + /// + /// + [] + val length: str:string -> int + + /// Builds a new string whose characters are the results of applying the function mapping + /// to each of the characters of the input string. + /// + /// The function to apply to the characters of the string. + /// The input string. + /// + /// The resulting string. + /// + /// Changing case to upper for all characters in the input string + /// + /// String.map System.Char.ToUpper "Hello there!" // evaluates "HELLO THERE!" + /// + /// + [] + val map: mapping:(char -> char) -> str:string -> string + + /// Builds a new string whose characters are the results of applying the function mapping + /// to each character and index of the input string. + /// + /// The function to apply to each character and index of the string. + /// The input string. + /// + /// The resulting string. + /// + /// Alternating case for all characters in the input string + /// + /// let alternateCase indx chr = + /// if 0 = indx % 2 + /// then System.Char.ToUpper chr + /// else System.Char.ToLower chr + /// String.mapi alternateCase "Hello there!" // evaluates "HeLlO ThErE!" + /// + /// + [] + val mapi: mapping:(int -> char -> char) -> str:string -> string /// Returns a string by concatenating count instances of str. /// @@ -126,14 +239,13 @@ namespace Microsoft.FSharp.Core /// /// The concatenated string. /// Thrown when count is negative. + /// + /// + /// + /// String.replicate 3 "Do it! " // evaluates "Do it! Do it! Do it! " + /// + /// [] val replicate: count:int -> str: string -> string - - /// Returns the length of the string. - /// - /// The input string. - /// - /// The number of characters in the string. - [] - val length: str:string -> int + From 712f32fdb1c8dad42300f0a583bd436c8d132da2 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Wed, 8 Sep 2021 18:08:32 +0300 Subject: [PATCH 05/14] Applying suggestions to the String examples --- src/fsharp/FSharp.Core/string.fsi | 99 +++++++++++++++++++------------ 1 file changed, 60 insertions(+), 39 deletions(-) diff --git a/src/fsharp/FSharp.Core/string.fsi b/src/fsharp/FSharp.Core/string.fsi index 62d8c86296b..6cd6683da9f 100644 --- a/src/fsharp/FSharp.Core/string.fsi +++ b/src/fsharp/FSharp.Core/string.fsi @@ -27,15 +27,16 @@ namespace Microsoft.FSharp.Core /// /// The concatenated string. /// - /// The following samples shows how to interspace spaces in a text + /// The following samples shows how to interspace spaces in a text /// - /// String.collect (sprintf "%c ") "Stefan says: Hi!" // evaluates "S t e f a n s a y s : H i ! " + /// let input = "Stefan says: Hi!" + /// input |> String.collect (sprintf "%c ") // evaluates "S t e f a n s a y s : H i ! " /// /// /// - /// How to show the ASCII representation of a very secret text: + /// How to show the ASCII representation of a very secret text /// - /// String.collect (fun chr -> int chr |> sprintf "%d ") "Secret" // evaluates "83 101 99 114 101 116 " + /// "Secret" |> String.collect (fun chr -> int chr |> sprintf "%d ") // evaluates "83 101 99 114 101 116 " /// /// [] @@ -51,11 +52,16 @@ namespace Microsoft.FSharp.Core /// the separation string. /// Thrown when strings is null. /// - /// + /// /// - /// String.concat " " ["Stefan"; "says:"; "Hello"; "there!"] // evaluates "Stefan says: Hello there!" - /// [0..9] |> List.map string |> String.concat "" // evaluates "0123456789" - /// String.concat "!" ["No exclamation point here"] // evaluates "No exclamation point here" + /// let input1 = ["Stefan"; "says:"; "Hello"; "there!"] + /// input1 |> String.concat " " // evaluates "Stefan says: Hello there!" + /// + /// let input2 = [0..9] |> List.map string + /// input2 |> String.concat "" // evaluates "0123456789" + /// + /// let input3 = ["No exclamation point here"] + /// input3 |> String.concat "!" // evaluates "No exclamation point here" /// /// [] @@ -68,10 +74,13 @@ namespace Microsoft.FSharp.Core /// /// True if any character returns true for the predicate and false otherwise. /// - /// Looking for uppercase characters + /// Looking for uppercase characters /// - /// String.exists System.Char.IsUpper "Yoda" // evaluates true - /// String.exists System.Char.IsUpper "nope" // evaluates false + /// open System + /// + /// "Yoda" |> String.exists Char.IsUpper // evaluates true + /// + /// "nope" |> String.exists Char.IsUpper // evaluates false /// /// [] @@ -87,10 +96,19 @@ namespace Microsoft.FSharp.Core /// /// The resulting string. /// - /// Filtering out just alphanumeric characters or just digits + /// Filtering out just alphanumeric characters + /// + /// open System + /// + /// let input = "0 1 2 3 4 5 6 7 8 9 a A m M" + /// input |> String.filter Uri.IsHexDigit // evaluates "123456789aA" + /// + /// + /// Filtering out just digits /// - /// String.filter System.Uri.IsHexDigit "0 1 2 3 4 5 6 7 8 9 a A m M" // evaluates "123456789aA" - /// String.filter System.Char.IsDigit "hello" // evaluates "" + /// open System + /// + /// "hello" |> String.filter Char.IsDigit // evaluates "" /// /// [] @@ -103,10 +121,13 @@ namespace Microsoft.FSharp.Core /// /// True if all characters return true for the predicate and false otherwise. /// - /// Looking for lowercase characters + /// Looking for lowercase characters /// - /// String.forall System.Char.IsLower "all are lower" // evaluates false - /// String.forall System.Char.IsLower "allarelower" // evaluates true + /// open System + /// + /// "all are lower" |> String.forall Char.IsLower // evaluates false + /// + /// "allarelower" |> String.forall Char.IsLower // evaluates true /// /// [] @@ -123,7 +144,7 @@ namespace Microsoft.FSharp.Core /// The constructed string. /// Thrown when count is negative. /// - /// Enumerate digits ASCII codes + /// Enumerate digits ASCII codes /// /// String.init 10 (fun i -> int '0' + i |> sprintf "%d ") // evaluates "48 49 50 51 52 53 54 55 56 57 " /// @@ -136,9 +157,10 @@ namespace Microsoft.FSharp.Core /// The function to be applied to each character of the string. /// The input string. /// - /// + /// Printing the ASCII code for each characater in the string /// - /// String.iter (fun c -> printfn "%c %d" c (int c)) "Hello" + /// let input = "Hello" + /// input |> String.iter (fun c -> printfn "%c %d" c (int c)) /// // evaluates unit /// // prints: /// H 72 @@ -157,17 +179,11 @@ namespace Microsoft.FSharp.Core /// The function to apply to each character and index of the string. /// The input string. /// - /// + /// Numbering the characters and printing the associated ASCII code + /// for each characater in the input string /// - /// String.length null // evaluates 0 - /// String.length "" // evaluates 0 - /// String.length "123" // evaluates 3 - /// - /// - /// - /// - /// - /// String.iteri (fun i c -> printfn "%d. %c %d" (i + 1) c (int c)) "Hello" + /// let input = "Hello" + /// input |> String.iteri (fun i c -> printfn "%d. %c %d" (i + 1) c (int c)) /// // evaluates unit /// // prints: /// 1. H 72 @@ -186,7 +202,7 @@ namespace Microsoft.FSharp.Core /// /// The number of characters in the string. /// - /// + /// Getting the length of different strings /// /// String.length null // evaluates 0 /// String.length "" // evaluates 0 @@ -204,9 +220,11 @@ namespace Microsoft.FSharp.Core /// /// The resulting string. /// - /// Changing case to upper for all characters in the input string + /// Changing case to upper for all characters in the input string /// - /// String.map System.Char.ToUpper "Hello there!" // evaluates "HELLO THERE!" + /// open System + /// let input = "Hello there!" + /// input |> String.map Char.ToUpper // evaluates "HELLO THERE!" /// /// [] @@ -220,13 +238,16 @@ namespace Microsoft.FSharp.Core /// /// The resulting string. /// - /// Alternating case for all characters in the input string + /// Alternating case for all characters in the input string /// + /// open System + /// /// let alternateCase indx chr = /// if 0 = indx % 2 - /// then System.Char.ToUpper chr - /// else System.Char.ToLower chr - /// String.mapi alternateCase "Hello there!" // evaluates "HeLlO ThErE!" + /// then Char.ToUpper chr + /// else Char.ToLower chr + /// let input = "Hello there!" + /// input |> String.mapi alternateCase // evaluates "HeLlO ThErE!" /// /// [] @@ -240,9 +261,9 @@ namespace Microsoft.FSharp.Core /// The concatenated string. /// Thrown when count is negative. /// - /// + /// /// - /// String.replicate 3 "Do it! " // evaluates "Do it! Do it! Do it! " + /// "Do it!" |> String.replicate 3 // evaluates "Do it!Do it!Do it!" /// /// [] From 04dc5d62fb786bea8ca03b06ab3c1c767697bbd1 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Wed, 8 Sep 2021 19:14:00 +0300 Subject: [PATCH 06/14] Following the suggestion that is more clear. --- src/fsharp/FSharp.Core/string.fsi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/fsharp/FSharp.Core/string.fsi b/src/fsharp/FSharp.Core/string.fsi index 6cd6683da9f..73174bc6bbd 100644 --- a/src/fsharp/FSharp.Core/string.fsi +++ b/src/fsharp/FSharp.Core/string.fsi @@ -58,10 +58,11 @@ namespace Microsoft.FSharp.Core /// input1 |> String.concat " " // evaluates "Stefan says: Hello there!" /// /// let input2 = [0..9] |> List.map string - /// input2 |> String.concat "" // evaluates "0123456789" + /// input2 |> String.concat "" // evaluates "0123456789" + /// input2 |> String.concat ", " // evaluates "0, 1, 2, 3, 4, 5, 6, 7, 8, 9" /// - /// let input3 = ["No exclamation point here"] - /// input3 |> String.concat "!" // evaluates "No exclamation point here" + /// let input3 = ["No comma"] + /// input3 |> String.concat "," // evaluates "No comma" /// /// [] From 596504341dc3b64091ed7c43b6cdb91cdfdbc935 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Thu, 9 Sep 2021 14:39:02 +0300 Subject: [PATCH 07/14] Partial work on the list examples --- src/fsharp/FSharp.Core/list.fsi | 157 +++++++++++++++++++++++++++++++- 1 file changed, 154 insertions(+), 3 deletions(-) diff --git a/src/fsharp/FSharp.Core/list.fsi b/src/fsharp/FSharp.Core/list.fsi index 4be7c133e23..c486c7abef7 100644 --- a/src/fsharp/FSharp.Core/list.fsi +++ b/src/fsharp/FSharp.Core/list.fsi @@ -22,6 +22,14 @@ namespace Microsoft.FSharp.Collections /// The second input list. /// /// The resulting list of pairs. + /// + /// + /// + /// let people = ["Kirk"; "Spock";"McCoy"] + /// let numbers = [1;2] + /// people |> List.allPairs numbers // evaluates [(1, "Kirk"); (1, "Spock"); (1, "McCoy"); (2, "Kirk"); (2, "Spock"); (2, "McCoy")] + /// + /// [] val allPairs: list1:'T1 list -> list2:'T2 list -> ('T1 * 'T2) list @@ -32,6 +40,14 @@ namespace Microsoft.FSharp.Collections /// The second input list. /// /// The resulting list. + /// + /// + /// + /// List.append [1..3] [4..7] // evaluates [1; 2; 3; 4; 5; 6; 7] + /// + /// [4..7] |> List.append [1..3] // evaluates [1; 2; 3; 4; 5; 6; 7] + /// + /// [] val append: list1:'T list -> list2:'T list -> 'T list @@ -43,10 +59,23 @@ namespace Microsoft.FSharp.Collections /// Thrown when the list is empty. /// /// The resulting average. + /// + /// + /// + /// [1.0 .. 9.0] |> List.average // evaluates 5.0 + /// + /// + /// + /// + /// + /// [1 .. 9] |> List.average // does not compile because error FS0001: The type 'int' does not support the operator 'DivideByInt' + /// (see averageBy example below for a solution) + /// + /// [] - val inline average : list:^T list -> ^T - when ^T : (static member ( + ) : ^T * ^T -> ^T) - and ^T : (static member DivideByInt : ^T*int -> ^T) + val inline average : list:^T list -> ^T + when ^T : (static member ( + ) : ^T * ^T -> ^T) + and ^T : (static member DivideByInt : ^T*int -> ^T) and ^T : (static member Zero : ^T) /// Returns the average of the elements generated by applying the function to each element of the list. @@ -58,6 +87,25 @@ namespace Microsoft.FSharp.Collections /// Thrown when the list is empty. /// /// The resulting average. + /// + /// Average the age of persons by extracting the age from records + /// + /// type People = { + /// name: string + /// age: int } + /// let getAgeAsFloat person = float person.age + /// let people = [ { name = "Kirk"; age = 26 } + /// { name = "Spock"; age = 90 } + /// { name = "McCoy"; age = 37 } ] + /// people |> List.averageBy getAgeAsFloat // evaluates 51.0 + /// + /// + /// + /// Average a list of integer numbers by converting to float + /// + /// [1 .. 9] |> List.averageBy float // evaluates 5.0 + /// + /// [] val inline averageBy : projection:('T -> ^U) -> list:'T list -> ^U when ^U : (static member ( + ) : ^U * ^U -> ^U) @@ -72,6 +120,37 @@ namespace Microsoft.FSharp.Collections /// The input list. /// /// The list comprising the values selected from the chooser function. + /// + /// + /// + /// type Happiness = AlwaysHappy | MostOfTheTimeGrumpy + /// type People = { + /// name: string + /// happiness: Happiness } + /// let takeJustHappyPersons person = + /// match person.happiness with + /// | AlwaysHappy -> Some person.name + /// | MostOfTheTimeGrumpy -> None + /// let candidatesForTheTrip = [ { name = "SpongeBob"; happiness = AlwaysHappy } + /// { name = "Patrick"; happiness = AlwaysHappy } + /// { name = "Squidward"; happiness = MostOfTheTimeGrumpy } ] + /// candidatesForTheTrip |> List.choose takeJustHappyPersons // evaluates [ "SpongeBob"; "Patrick" ] + /// + /// + /// + /// + /// + /// // Using the identity function "id" (is defined like fun x -> x) + /// let input1 = [ Some 1; None; Some 3; None ] + /// input1 |> List.choose id // evaluates [1; 3] + /// + /// let input2: int option list = [] + /// input2 |> List.choose id // evaluates [] (notice that has the type "int list") + /// + /// let input3: string option list =[ None; None ] + /// input3 |> List.choose id // evaluates [] (notice that has the type "string list") + /// + /// [] val choose: chooser:('T -> 'U option) -> list:'T list -> 'U list @@ -83,6 +162,17 @@ namespace Microsoft.FSharp.Collections /// The list divided into chunks. /// /// Thrown when chunkSize is not positive. + /// + /// + /// + /// [1 .. 10 ] |> List.chunkBySize 3 // evaluates [[1; 2; 3]; [4; 5; 6]; [7; 8; 9]; [10]] (notice the last chunk) + /// + /// [1 .. 5 ] |> List.chunkBySize 10 // evaluates [[1; 2; 3; 4; 5]] + /// + /// let input : string list = [] + /// input |> List.chunkBySize 10 // evaluates [] (notice that has the type "string list list") + /// + /// [] val chunkBySize: chunkSize:int -> list:'T list -> 'T list list @@ -92,6 +182,12 @@ namespace Microsoft.FSharp.Collections /// The input list. /// /// The concatenation of the transformed sublists. + /// + /// For each positive number in the array we are generating all the previous positive numbers + /// + /// [1..4] |> List.collect (fun x -> [1..x]) // evaluates [1; 1; 2; 1; 2; 3; 1; 2; 3; 4] + /// + /// [] val collect: mapping:('T -> 'U list) -> list:'T list -> 'U list @@ -115,6 +211,15 @@ namespace Microsoft.FSharp.Collections /// The input sequence of lists. /// /// The resulting concatenated list. + /// + /// + /// + /// let input = [ [1;2] + /// [3;4;5] + /// [6;7;8;9] ] + /// input |> List.concat // evaluates [1; 2; 3; 4; 5; 6; 7; 8; 9] + /// + /// [] val concat: lists:seq<'T list> -> 'T list @@ -124,6 +229,18 @@ namespace Microsoft.FSharp.Collections /// The input list. /// /// True if the input list contains the specified element; false otherwise. + /// + /// + /// + /// [1..9] |> List.contains 0 // evaluates false + /// + /// [1..9] |> List.contains 3 // evaluates true + /// + /// let input = [1, "SpongeBob"; 2, "Patrick"; 3, "Squidward"; 4, "Mr. Krabs"] + /// input |> List.contains (2, "Patrick") // evaluates true + /// input |> List.contains (22, "Patrick") // evaluates false + /// + /// [] val inline contains: value:'T -> source:'T list -> bool when 'T : equality @@ -134,6 +251,13 @@ namespace Microsoft.FSharp.Collections /// The input list. /// /// The result list. + /// + /// + /// + /// let input = [6;1;2;3;1;4;5;5] + /// input |> List.distinct // evaluates [6; 1; 2; 3; 4; 5] + /// + /// [] val distinct: list:'T list -> 'T list when 'T : equality @@ -145,6 +269,14 @@ namespace Microsoft.FSharp.Collections /// The input list. /// /// The result list. + /// + /// + /// + /// let isEven x = 0 = x % 2 + /// let input = [6;1;2;3;1;4;5;5] + /// input |> List.distinctBy isEven // evaluates [6; 1] + /// + /// [] val distinctBy: projection:('T -> 'Key) -> list:'T list -> 'T list when 'Key : equality @@ -156,6 +288,18 @@ namespace Microsoft.FSharp.Collections /// The input list. /// /// The result list. + /// + /// + /// + /// let isEven x = 0 = x % 2 + /// let reminderOfTheDivisionBy3 x = x % 3 + /// let input = [6; 1; 2; 3; 1; 4; 5; 5] + /// + /// input |> List.countBy isEven // evaluates [(true, 3); (false, 5)] + /// + /// input |> List.countBy reminderOfTheDivisionBy3 // evaluates [(0, 2); (1, 3); (2, 3)] + /// + /// [] val countBy : projection:('T -> 'Key) -> list:'T list -> ('Key * int) list when 'Key : equality @@ -167,6 +311,13 @@ namespace Microsoft.FSharp.Collections /// The list split into chunks. /// /// Thrown when count is not positive. + /// + /// + /// + /// [1..10] |> List.splitInto 2 // evaluates [[1; 2; 3; 4; 5]; [6; 7; 8; 9; 10]] + /// [1..10] |> List.splitInto 4 // evaluates [[1; 2; 3]; [4; 5; 6]; [7; 8]; [9; 10]] + /// + /// [] val splitInto: count:int -> list:'T list -> 'T list list From d3d2ee7ce4aa4d326cc1eb262a0d85d1445f8e3c Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Thu, 9 Sep 2021 18:42:58 +0300 Subject: [PATCH 08/14] Small refactor of examples as requested by reviewer --- src/fsharp/FSharp.Core/string.fsi | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/fsharp/FSharp.Core/string.fsi b/src/fsharp/FSharp.Core/string.fsi index 73174bc6bbd..a77d4cbb160 100644 --- a/src/fsharp/FSharp.Core/string.fsi +++ b/src/fsharp/FSharp.Core/string.fsi @@ -30,14 +30,16 @@ namespace Microsoft.FSharp.Core /// The following samples shows how to interspace spaces in a text /// /// let input = "Stefan says: Hi!" - /// input |> String.collect (sprintf "%c ") // evaluates "S t e f a n s a y s : H i ! " + /// input |> String.collect (sprintf "%c ") /// + /// The sample evaluates to "S t e f a n s a y s : H i ! " /// /// /// How to show the ASCII representation of a very secret text /// - /// "Secret" |> String.collect (fun chr -> int chr |> sprintf "%d ") // evaluates "83 101 99 114 101 116 " + /// "Secret" |> String.collect (fun chr -> int chr |> sprintf "%d ") /// + /// The sample evaluates to "83 101 99 114 101 116 " /// [] val collect: mapping:(char -> string) -> str:string -> string @@ -147,8 +149,9 @@ namespace Microsoft.FSharp.Core /// /// Enumerate digits ASCII codes /// - /// String.init 10 (fun i -> int '0' + i |> sprintf "%d ") // evaluates "48 49 50 51 52 53 54 55 56 57 " + /// String.init 10 (fun i -> int '0' + i |> sprintf "%d ") /// + /// The sample evaluates to: "48 49 50 51 52 53 54 55 56 57 " /// [] val init: count:int -> initializer:(int -> string) -> string @@ -162,8 +165,9 @@ namespace Microsoft.FSharp.Core /// /// let input = "Hello" /// input |> String.iter (fun c -> printfn "%c %d" c (int c)) - /// // evaluates unit - /// // prints: + /// + /// The sample evaluates as unit, but prints: + /// /// H 72 /// e 101 /// l 108 @@ -185,8 +189,9 @@ namespace Microsoft.FSharp.Core /// /// let input = "Hello" /// input |> String.iteri (fun i c -> printfn "%d. %c %d" (i + 1) c (int c)) - /// // evaluates unit - /// // prints: + /// + /// The sample evaluates as unit, but prints: + /// /// 1. H 72 /// 2. e 101 /// 3. l 108 From d29da4d64e819cbf47f8c5eb99b4c5c00d2bc0fb Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Thu, 9 Sep 2021 18:44:05 +0300 Subject: [PATCH 09/14] Refactor of List examples following guidelines from previous reviews --- src/fsharp/FSharp.Core/list.fsi | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/fsharp/FSharp.Core/list.fsi b/src/fsharp/FSharp.Core/list.fsi index c486c7abef7..308e7985228 100644 --- a/src/fsharp/FSharp.Core/list.fsi +++ b/src/fsharp/FSharp.Core/list.fsi @@ -27,7 +27,11 @@ namespace Microsoft.FSharp.Collections /// /// let people = ["Kirk"; "Spock";"McCoy"] /// let numbers = [1;2] - /// people |> List.allPairs numbers // evaluates [(1, "Kirk"); (1, "Spock"); (1, "McCoy"); (2, "Kirk"); (2, "Spock"); (2, "McCoy")] + /// people |> List.allPairs numbers + /// + /// The sample evaluates to + /// + /// [(1, "Kirk"); (1, "Spock"); (1, "McCoy"); (2, "Kirk"); (2, "Spock"); (2, "McCoy")] /// /// [] @@ -68,9 +72,10 @@ namespace Microsoft.FSharp.Collections /// /// /// - /// [1 .. 9] |> List.average // does not compile because error FS0001: The type 'int' does not support the operator 'DivideByInt' - /// (see averageBy example below for a solution) + /// [1 .. 9] |> List.average /// + /// The sample does not compile because The type 'int' does not support the operator 'DivideByInt' + /// (see averageBy examples for a solution) /// [] val inline average : list:^T list -> ^T @@ -134,8 +139,9 @@ namespace Microsoft.FSharp.Collections /// let candidatesForTheTrip = [ { name = "SpongeBob"; happiness = AlwaysHappy } /// { name = "Patrick"; happiness = AlwaysHappy } /// { name = "Squidward"; happiness = MostOfTheTimeGrumpy } ] - /// candidatesForTheTrip |> List.choose takeJustHappyPersons // evaluates [ "SpongeBob"; "Patrick" ] + /// candidatesForTheTrip |> List.choose takeJustHappyPersons /// + /// The sample evaluates to [ "SpongeBob"; "Patrick" ] /// /// /// @@ -165,13 +171,20 @@ namespace Microsoft.FSharp.Collections /// /// /// - /// [1 .. 10 ] |> List.chunkBySize 3 // evaluates [[1; 2; 3]; [4; 5; 6]; [7; 8; 9]; [10]] (notice the last chunk) + /// [1 .. 10 ] |> List.chunkBySize 3 // evaluates + /// + /// Evaluates to [[1; 2; 3]; [4; 5; 6]; [7; 8; 9]; [10]] . Please notice the last chunk. /// - /// [1 .. 5 ] |> List.chunkBySize 10 // evaluates [[1; 2; 3; 4; 5]] + /// + /// let output2 = [1 .. 5 ] |> List.chunkBySize 10 + /// + /// Evaluates to [[1; 2; 3; 4; 5]] /// + /// /// let input : string list = [] - /// input |> List.chunkBySize 10 // evaluates [] (notice that has the type "string list list") + /// let output3 = input |> List.chunkBySize 10 /// + /// Evaluates to []. Please notice that has the type string list list. /// [] val chunkBySize: chunkSize:int -> list:'T list -> 'T list list @@ -185,8 +198,9 @@ namespace Microsoft.FSharp.Collections /// /// For each positive number in the array we are generating all the previous positive numbers /// - /// [1..4] |> List.collect (fun x -> [1..x]) // evaluates [1; 1; 2; 1; 2; 3; 1; 2; 3; 4] + /// [1..4] |> List.collect (fun x -> [1..x]) /// + /// The sample evaluates to [1; 1; 2; 1; 2; 3; 1; 2; 3; 4] (added extra spaces for easy reading) /// [] val collect: mapping:('T -> 'U list) -> list:'T list -> 'U list From bcd591397c67dba265b419e5b0654ab8c3924b05 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Fri, 10 Sep 2021 18:29:55 +0300 Subject: [PATCH 10/14] More examples for the List module --- src/fsharp/FSharp.Core/list.fsi | 109 +++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/src/fsharp/FSharp.Core/list.fsi b/src/fsharp/FSharp.Core/list.fsi index 308e7985228..fad34d06af3 100644 --- a/src/fsharp/FSharp.Core/list.fsi +++ b/src/fsharp/FSharp.Core/list.fsi @@ -303,7 +303,7 @@ namespace Microsoft.FSharp.Collections /// /// The result list. /// - /// + /// /// /// let isEven x = 0 = x % 2 /// let reminderOfTheDivisionBy3 x = x % 3 @@ -350,6 +350,20 @@ namespace Microsoft.FSharp.Collections /// A list that contains the distinct elements of list that do not appear in itemsToExclude. /// /// Thrown when itemsToExclude is null. + /// + /// + /// + /// let input = [1, "Kirk"; 2, "Spock"; 3, "Kenobi"] + /// input |> List.except [3, "Kenobi"] // evaluates [(1, "Kirk"); (2, "Spock")] + /// + /// + /// + /// + /// + /// [0..10] |> List.except [1..5] // evaluates [0; 6; 7; 8; 9; 10] + /// [1..5] |> List.except [0..10] // evaluates [] + /// + /// [] val except: itemsToExclude:seq<'T> -> list:'T list -> 'T list when 'T : equality @@ -360,6 +374,12 @@ namespace Microsoft.FSharp.Collections /// The only element of the list. /// /// Thrown when the input does not have precisely one element. + /// + /// + /// + /// ["the chosen one"] |> List.exactlyOne // evaluates "the chosen one" + /// + /// [] val exactlyOne: list:'T list -> 'T @@ -368,6 +388,13 @@ namespace Microsoft.FSharp.Collections /// The input list. /// /// The only element of the list or None. + /// + /// + /// + /// [1] |> List.tryExactlyOne // evaluates Some 1 + /// [1;2] |> List.tryExactlyOne // evaluates None + /// + /// [] val tryExactlyOne: list:'T list -> 'T option @@ -380,6 +407,16 @@ namespace Microsoft.FSharp.Collections /// The input list. /// /// True if any element satisfies the predicate. + /// + /// + /// + /// let input = [1, "Kirk"; 2, "Spock"; 3, "Kenobi"] + /// + /// input |> List.exists (fun x -> x = (3, "Kenobi")) // evaluates true + /// + /// input |> List.exists (fun (nr, name) -> nr > 5) // evaluates false + /// + /// [] val exists: predicate:('T -> bool) -> list:'T list -> bool @@ -398,6 +435,16 @@ namespace Microsoft.FSharp.Collections /// Thrown when the input lists differ in length. /// /// True if any pair of elements satisfy the predicate. + /// + /// Check if the sum of pairs (from 2 different lists) have at least one even number + /// + /// let anEvenSum a b = 0 = (a + b) % 2 + /// + /// [1..4] |> List.exists2 anEvenSum [2..5] // evaluates false + /// + /// [1..4] |> List.exists2 anEvenSum [2;4;5;6] // evaluates true + /// + /// [] val exists2: predicate:('T1 -> 'T2 -> bool) -> list1:'T1 list -> list2:'T2 list -> bool @@ -411,6 +458,17 @@ namespace Microsoft.FSharp.Collections /// all the elements of the list. /// /// The first element that satisfies the predicate. + /// + /// + /// + /// let isEven x = 0 = x % 2 + /// let isGreaterThan x y = y > x + /// let input = [1, "Luke"; 2, "Kirk"; 3, "Spock"; 4, "Kenobi"] + /// + /// input |> List.find (fst >> isEven) // evaluates (2, "Kirk") + /// input |> List.find (fst >> isGreaterThan 6) // raises an exception + /// + /// [] val find: predicate:('T -> bool) -> list:'T list -> 'T @@ -424,6 +482,17 @@ namespace Microsoft.FSharp.Collections /// all the elements of the list. /// /// The last element that satisfies the predicate. + /// + /// + /// + /// let isEven x = 0 = x % 2 + /// let isGreaterThan x y = y > x + /// let input = [1, "Luke"; 2, "Kirk"; 3, "Spock"; 4, "Kenobi"] + /// + /// input |> List.findBack (fst >> isEven) // evaluates (4, "Kenobi") + /// input |> List.findBack (fst >> isGreaterThan 6) // raises an exception + /// + /// [] val findBack: predicate:('T -> bool) -> list:'T list -> 'T @@ -438,6 +507,17 @@ namespace Microsoft.FSharp.Collections /// elements of the list. /// /// The index of the first element that satisfies the predicate. + /// + /// + /// + /// let isEven x = 0 = x % 2 + /// let isGreaterThan x y = y > x + /// let input = [1, "Luke"; 2, "Kirk"; 3, "Spock"; 4, "Kenobi"] + /// + /// input |> List.findIndex (fst >> isEven) // evaluates 1 + /// input |> List.findIndex (fst >> isGreaterThan 6) // raises an exception + /// + /// [] val findIndex: predicate:('T -> bool) -> list:'T list -> int @@ -452,6 +532,17 @@ namespace Microsoft.FSharp.Collections /// elements of the list. /// /// The index of the last element that satisfies the predicate. + /// + /// + /// + /// let isEven x = 0 = x % 2 + /// let isGreaterThan x y = y > x + /// let input = [1, "Luke"; 2, "Kirk"; 3, "Spock"; 4, "Kenobi"] + /// + /// input |> List.findIndexBack (fst >> isEven) // evaluates 3 + /// input |> List.findIndexBack (fst >> isGreaterThan 6) // raises an exception + /// + /// [] val findIndexBack: predicate:('T -> bool) -> list:'T list -> int @@ -462,6 +553,16 @@ namespace Microsoft.FSharp.Collections /// The input list. /// /// A list containing only the elements that satisfy the predicate. + /// + /// + /// + /// let input = [1, "Luke"; 2, "Kirk"; 3, "Kenobi"; 4, "Spock"] + /// let isComingFromStarTrek = fst >> isEven + /// + /// input |> List.filter isComingFromStarTrek + /// + /// Evaluates to [(2, "Kirk"); (4, "Spock")] + /// [] val filter: predicate:('T -> bool) -> list:'T list -> 'T list @@ -477,6 +578,12 @@ namespace Microsoft.FSharp.Collections /// The input list. /// /// The final state value. + /// + /// Making the sum of squares for the first 5 natural numbers + /// + /// [1..5] |> List.fold (fun s v -> s + v * v ) 0 // evaluates 55 + /// + /// [] val fold<'T,'State> : folder:('State -> 'T -> 'State) -> state:'State -> list:'T list -> 'State From 05d06a4196555302d78ab8141ed45c23a4a55e40 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Sat, 11 Sep 2021 21:15:13 +0300 Subject: [PATCH 11/14] Examples for fold and foldBack --- src/fsharp/FSharp.Core/list.fsi | 50 +++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/src/fsharp/FSharp.Core/list.fsi b/src/fsharp/FSharp.Core/list.fsi index fad34d06af3..953c8498109 100644 --- a/src/fsharp/FSharp.Core/list.fsi +++ b/src/fsharp/FSharp.Core/list.fsi @@ -25,7 +25,7 @@ namespace Microsoft.FSharp.Collections /// /// /// - /// let people = ["Kirk"; "Spock";"McCoy"] + /// let people = ["Kirk"; "Spock"; "McCoy"] /// let numbers = [1;2] /// people |> List.allPairs numbers /// @@ -391,7 +391,7 @@ namespace Microsoft.FSharp.Collections /// /// /// - /// [1] |> List.tryExactlyOne // evaluates Some 1 + /// [1] |> List.tryExactlyOne // evaluates Some 1 /// [1;2] |> List.tryExactlyOne // evaluates None /// /// @@ -579,11 +579,33 @@ namespace Microsoft.FSharp.Collections /// /// The final state value. /// - /// Making the sum of squares for the first 5 natural numbers + /// Making the sum of squares for the first 5 natural numbers /// /// [1..5] |> List.fold (fun s v -> s + v * v ) 0 // evaluates 55 /// /// + /// + /// Shoping for fruits hungry, you tend to take more of each as the hunger grows + /// + /// type Fruit = Apple | Pear | Orange + /// type BagItem = { fruit: Fruit; quantity: int } + /// let takeMore (previous: BagItem list) fruit = + /// let toTakeThisTime = + /// match previous with + /// | bagItem :: otherBagItems -> bagItem.quantity + 1 + /// | [] -> 1 + /// { fruit = fruit; quantity = toTakeThisTime } :: previous + /// let input = [ Apple; Pear; Orange ] + /// + /// input |> List.fold takeMore [] + /// + /// Evaluates to + /// + /// [{ fruit = Orange; quantity = 3 } + /// { fruit = Pear; quantity = 2 } + /// { fruit = Apple; quantity = 1 }] + /// + /// [] val fold<'T,'State> : folder:('State -> 'T -> 'State) -> state:'State -> list:'T list -> 'State @@ -610,6 +632,28 @@ namespace Microsoft.FSharp.Collections /// The initial state. /// /// The state object after the folding function is applied to each element of the list. + /// + /// Shoping for fruits hungry, you tend to take more of each as the hunger grows + /// + /// type Fruit = Apple | Pear | Orange + /// type BagItem = { fruit: Fruit; quantity: int } + /// let takeMore fruit (previous: BagItem list) = + /// let toTakeThisTime = + /// match previous with + /// | bagItem :: otherBagItems -> bagItem.quantity + 1 + /// | [] -> 1 + /// { fruit = fruit; quantity = toTakeThisTime } :: previous + /// let input = [ Apple; Pear; Orange ] + /// + /// [] |> List.foldBack takeMore input + /// + /// Evaluates to + /// + /// [{ fruit = Apple; quantity = 3 } + /// { fruit = Pear; quantity = 2 } + /// { fruit = Orange; quantity = 3 }] + /// + /// [] val foldBack<'T,'State> : folder:('T -> 'State -> 'State) -> list:'T list -> state:'State -> 'State From 734aed515a362fc41c12d8263b11c2aa3abc81e2 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Tue, 14 Sep 2021 23:43:27 +0300 Subject: [PATCH 12/14] Applied the review suggestions to the List module exapmples --- src/fsharp/FSharp.Core/list.fsi | 94 +++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 34 deletions(-) diff --git a/src/fsharp/FSharp.Core/list.fsi b/src/fsharp/FSharp.Core/list.fsi index 953c8498109..68ed27ae5ef 100644 --- a/src/fsharp/FSharp.Core/list.fsi +++ b/src/fsharp/FSharp.Core/list.fsi @@ -99,9 +99,10 @@ namespace Microsoft.FSharp.Collections /// name: string /// age: int } /// let getAgeAsFloat person = float person.age - /// let people = [ { name = "Kirk"; age = 26 } - /// { name = "Spock"; age = 90 } - /// { name = "McCoy"; age = 37 } ] + /// let people = + /// [ { name = "Kirk"; age = 26 } + /// { name = "Spock"; age = 90 } + /// { name = "McCoy"; age = 37 } ] /// people |> List.averageBy getAgeAsFloat // evaluates 51.0 /// /// @@ -136,9 +137,10 @@ namespace Microsoft.FSharp.Collections /// match person.happiness with /// | AlwaysHappy -> Some person.name /// | MostOfTheTimeGrumpy -> None - /// let candidatesForTheTrip = [ { name = "SpongeBob"; happiness = AlwaysHappy } - /// { name = "Patrick"; happiness = AlwaysHappy } - /// { name = "Squidward"; happiness = MostOfTheTimeGrumpy } ] + /// let candidatesForTheTrip = + /// [ { name = "SpongeBob"; happiness = AlwaysHappy } + /// { name = "Patrick"; happiness = AlwaysHappy } + /// { name = "Squidward"; happiness = MostOfTheTimeGrumpy } ] /// candidatesForTheTrip |> List.choose takeJustHappyPersons /// /// The sample evaluates to [ "SpongeBob"; "Patrick" ] @@ -303,16 +305,12 @@ namespace Microsoft.FSharp.Collections /// /// The result list. /// - /// + /// Counting the number of occurrences of chars /// - /// let isEven x = 0 = x % 2 - /// let reminderOfTheDivisionBy3 x = x % 3 - /// let input = [6; 1; 2; 3; 1; 4; 5; 5] - /// - /// input |> List.countBy isEven // evaluates [(true, 3); (false, 5)] - /// - /// input |> List.countBy reminderOfTheDivisionBy3 // evaluates [(0, 2); (1, 3); (2, 3)] + /// let input = ['H'; 'a'; 'p'; 'p'; 'i'; 'n'; 'e'; 's'; 's'] + /// input |> List.countBy id /// + /// Evalutes [('H', 1); ('a', 1); ('p', 2); ('i', 1); ('n', 1); ('e', 1); ('s', 2)] /// [] val countBy : projection:('T -> 'Key) -> list:'T list -> ('Key * int) list when 'Key : equality @@ -380,6 +378,21 @@ namespace Microsoft.FSharp.Collections /// ["the chosen one"] |> List.exactlyOne // evaluates "the chosen one" /// /// + /// + /// + /// + /// let input : string list = [] + /// input |> List.exactlyOne + /// + /// Will throw the exception: System.ArgumentException: The input sequence was empty + /// + /// + /// + /// + /// [1..5] |> List.exactlyOne + /// + /// Will throw the exception: System.ArgumentException: The input sequence contains more than one element + /// [] val exactlyOne: list:'T list -> 'T @@ -391,8 +404,9 @@ namespace Microsoft.FSharp.Collections /// /// /// - /// [1] |> List.tryExactlyOne // evaluates Some 1 - /// [1;2] |> List.tryExactlyOne // evaluates None + /// [1] |> List.tryExactlyOne // evaluates Some 1 + /// [1;2] |> List.tryExactlyOne // evaluates None + /// ([] : int list) |> List.tryExactlyOne // evaluates None /// /// [] @@ -414,7 +428,7 @@ namespace Microsoft.FSharp.Collections /// /// input |> List.exists (fun x -> x = (3, "Kenobi")) // evaluates true /// - /// input |> List.exists (fun (nr, name) -> nr > 5) // evaluates false + /// input |> List.exists (fun (n, name) -> n > 5) // evaluates false /// /// [] @@ -440,9 +454,11 @@ namespace Microsoft.FSharp.Collections /// /// let anEvenSum a b = 0 = (a + b) % 2 /// - /// [1..4] |> List.exists2 anEvenSum [2..5] // evaluates false + /// ([1..4], [2..5]) + /// ||> List.exists2 anEvenSum // evaluates false /// - /// [1..4] |> List.exists2 anEvenSum [2;4;5;6] // evaluates true + /// ([1..4], [2;4;5;6]) + /// ||> List.exists2 anEvenSum // evaluates true /// /// [] @@ -465,8 +481,8 @@ namespace Microsoft.FSharp.Collections /// let isGreaterThan x y = y > x /// let input = [1, "Luke"; 2, "Kirk"; 3, "Spock"; 4, "Kenobi"] /// - /// input |> List.find (fst >> isEven) // evaluates (2, "Kirk") - /// input |> List.find (fst >> isGreaterThan 6) // raises an exception + /// input |> List.find (fun (x,_) -> isEven x) // evaluates (2, "Kirk") + /// input |> List.find (fun (x,_) -> x |> isGreaterThan 6) // raises an exception /// /// [] @@ -489,8 +505,8 @@ namespace Microsoft.FSharp.Collections /// let isGreaterThan x y = y > x /// let input = [1, "Luke"; 2, "Kirk"; 3, "Spock"; 4, "Kenobi"] /// - /// input |> List.findBack (fst >> isEven) // evaluates (4, "Kenobi") - /// input |> List.findBack (fst >> isGreaterThan 6) // raises an exception + /// input |> List.findBack (fun (x,_) -> isEven x) // evaluates (4, "Kenobi") + /// input |> List.findBack (fun (x,_) -> x |> isGreaterThan 6) // raises an exception /// /// [] @@ -514,8 +530,8 @@ namespace Microsoft.FSharp.Collections /// let isGreaterThan x y = y > x /// let input = [1, "Luke"; 2, "Kirk"; 3, "Spock"; 4, "Kenobi"] /// - /// input |> List.findIndex (fst >> isEven) // evaluates 1 - /// input |> List.findIndex (fst >> isGreaterThan 6) // raises an exception + /// input |> List.findIndex (fun (x,_) -> isEven x) // evaluates 1 + /// input |> List.findIndex (fun (x,_) -> x |> isGreaterThan 6) // raises an exception /// /// [] @@ -539,8 +555,8 @@ namespace Microsoft.FSharp.Collections /// let isGreaterThan x y = y > x /// let input = [1, "Luke"; 2, "Kirk"; 3, "Spock"; 4, "Kenobi"] /// - /// input |> List.findIndexBack (fst >> isEven) // evaluates 3 - /// input |> List.findIndexBack (fst >> isGreaterThan 6) // raises an exception + /// input |> List.findIndexBack (fun (x,_) -> isEven x) // evaluates 3 + /// input |> List.findIndexBack (fun (x,_) -> x |> isGreaterThan 6) // raises an exception /// /// [] @@ -557,7 +573,7 @@ namespace Microsoft.FSharp.Collections /// /// /// let input = [1, "Luke"; 2, "Kirk"; 3, "Kenobi"; 4, "Spock"] - /// let isComingFromStarTrek = fst >> isEven + /// let isComingFromStarTrek (x,_) = isEven x /// /// input |> List.filter isComingFromStarTrek /// @@ -581,11 +597,12 @@ namespace Microsoft.FSharp.Collections /// /// Making the sum of squares for the first 5 natural numbers /// - /// [1..5] |> List.fold (fun s v -> s + v * v ) 0 // evaluates 55 + /// (0, [1..5]) + /// ||> List.fold (fun s v -> s + v * v ) // evaluates 55 /// /// /// - /// Shoping for fruits hungry, you tend to take more of each as the hunger grows + /// Shopping for fruits hungry, you tend to take more of each as the hunger grows /// /// type Fruit = Apple | Pear | Orange /// type BagItem = { fruit: Fruit; quantity: int } @@ -597,7 +614,8 @@ namespace Microsoft.FSharp.Collections /// { fruit = fruit; quantity = toTakeThisTime } :: previous /// let input = [ Apple; Pear; Orange ] /// - /// input |> List.fold takeMore [] + /// ([], input) + /// ||> List.fold takeMore /// /// Evaluates to /// @@ -633,7 +651,14 @@ namespace Microsoft.FSharp.Collections /// /// The state object after the folding function is applied to each element of the list. /// - /// Shoping for fruits hungry, you tend to take more of each as the hunger grows + /// Making the sum of squares for the first 5 natural numbers + /// + /// ([1..5], 0) + /// ||> List.foldBack (fun v s -> s + v * v ) // evaluates 55 + /// + /// + /// + /// Shopping for fruits hungry, you tend to take more of each as the hunger grows /// /// type Fruit = Apple | Pear | Orange /// type BagItem = { fruit: Fruit; quantity: int } @@ -645,13 +670,14 @@ namespace Microsoft.FSharp.Collections /// { fruit = fruit; quantity = toTakeThisTime } :: previous /// let input = [ Apple; Pear; Orange ] /// - /// [] |> List.foldBack takeMore input + /// (input, []) + /// ||> List.foldBack takeMore /// /// Evaluates to /// /// [{ fruit = Apple; quantity = 3 } /// { fruit = Pear; quantity = 2 } - /// { fruit = Orange; quantity = 3 }] + /// { fruit = Orange; quantity = 1 }] /// /// [] From 66c24a6308b86c77c4481d497f10a8da78402858 Mon Sep 17 00:00:00 2001 From: Mecu Stefan Date: Wed, 15 Sep 2021 00:28:09 +0300 Subject: [PATCH 13/14] Applied the review suggestions to the List module exapmples --- src/fsharp/FSharp.Core/list.fsi | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/fsharp/FSharp.Core/list.fsi b/src/fsharp/FSharp.Core/list.fsi index 68ed27ae5ef..5cabd4a1604 100644 --- a/src/fsharp/FSharp.Core/list.fsi +++ b/src/fsharp/FSharp.Core/list.fsi @@ -597,8 +597,7 @@ namespace Microsoft.FSharp.Collections /// /// Making the sum of squares for the first 5 natural numbers /// - /// (0, [1..5]) - /// ||> List.fold (fun s v -> s + v * v ) // evaluates 55 + /// (0, [1..5]) ||> List.fold (fun s v -> s + v * v ) // evaluates 55 /// /// /// @@ -614,8 +613,7 @@ namespace Microsoft.FSharp.Collections /// { fruit = fruit; quantity = toTakeThisTime } :: previous /// let input = [ Apple; Pear; Orange ] /// - /// ([], input) - /// ||> List.fold takeMore + /// ([], input) ||> List.fold takeMore /// /// Evaluates to /// @@ -653,8 +651,7 @@ namespace Microsoft.FSharp.Collections /// /// Making the sum of squares for the first 5 natural numbers /// - /// ([1..5], 0) - /// ||> List.foldBack (fun v s -> s + v * v ) // evaluates 55 + /// ([1..5], 0) ||> List.foldBack (fun v s -> s + v * v ) // evaluates 55 /// /// /// @@ -670,8 +667,7 @@ namespace Microsoft.FSharp.Collections /// { fruit = fruit; quantity = toTakeThisTime } :: previous /// let input = [ Apple; Pear; Orange ] /// - /// (input, []) - /// ||> List.foldBack takeMore + /// (input, []) ||> List.foldBack takeMore /// /// Evaluates to /// From 421100faae81273856602116d6a9940ec8d405c0 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Tue, 14 Sep 2021 23:15:48 +0100 Subject: [PATCH 14/14] Update list.fsi --- src/fsharp/FSharp.Core/list.fsi | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/fsharp/FSharp.Core/list.fsi b/src/fsharp/FSharp.Core/list.fsi index 5cabd4a1604..906b2028cb9 100644 --- a/src/fsharp/FSharp.Core/list.fsi +++ b/src/fsharp/FSharp.Core/list.fsi @@ -53,7 +53,7 @@ namespace Microsoft.FSharp.Collections /// /// [] - val append: list1:'T list -> list2:'T list -> 'T list + val append: list1: 'T list -> list2: 'T list -> 'T list /// Returns the average of the elements in the list. /// @@ -79,7 +79,7 @@ namespace Microsoft.FSharp.Collections /// [] val inline average : list:^T list -> ^T - when ^T : (static member ( + ) : ^T * ^T -> ^T) + when ^T : (static member (+) : ^T * ^T -> ^T) and ^T : (static member DivideByInt : ^T*int -> ^T) and ^T : (static member Zero : ^T) @@ -113,8 +113,8 @@ namespace Microsoft.FSharp.Collections /// /// [] - val inline averageBy : projection:('T -> ^U) -> list:'T list -> ^U - when ^U : (static member ( + ) : ^U * ^U -> ^U) + val inline averageBy: projection:('T -> ^U) -> list:'T list -> ^U + when ^U : (static member (+) : ^U * ^U -> ^U) and ^U : (static member DivideByInt : ^U*int -> ^U) and ^U : (static member Zero : ^U) @@ -597,7 +597,7 @@ namespace Microsoft.FSharp.Collections /// /// Making the sum of squares for the first 5 natural numbers /// - /// (0, [1..5]) ||> List.fold (fun s v -> s + v * v ) // evaluates 55 + /// (0, [1..5]) ||> List.fold (fun s v -> s + v * v) // evaluates 55 /// /// /// @@ -651,7 +651,7 @@ namespace Microsoft.FSharp.Collections /// /// Making the sum of squares for the first 5 natural numbers /// - /// ([1..5], 0) ||> List.foldBack (fun v s -> s + v * v ) // evaluates 55 + /// ([1..5], 0) ||> List.foldBack (fun v s -> s + v * v) // evaluates 55 /// /// /// @@ -1205,7 +1205,7 @@ namespace Microsoft.FSharp.Collections /// The resulting sum. [] val inline sum : list:^T list -> ^T - when ^T : (static member ( + ) : ^T * ^T -> ^T) + when ^T : (static member (+) : ^T * ^T -> ^T) and ^T : (static member Zero : ^T) /// Returns the sum of the results generated by applying the function to each element of the list. @@ -1216,7 +1216,7 @@ namespace Microsoft.FSharp.Collections /// The resulting sum. [] val inline sumBy : projection:('T -> ^U) -> list:'T list -> ^U - when ^U : (static member ( + ) : ^U * ^U -> ^U) + when ^U : (static member (+) : ^U * ^U -> ^U) and ^U : (static member Zero : ^U) /// Returns the list after removing the first element.