C# conformance
C# that behaves like .NET in the browser
Every case below is a piece of C# run twice: on .NET, and as the JavaScript WebSharper compiles it to. The results are compared character by character. Where they differ, it is listed as a known difference, with what to write instead.
Same result as .NET
95.0%
322 of 339 cases
Known differences
17
where JavaScript itself differs, each with an alternative
Unexplained differences
0
silent mismatches; 0 cases rejected at compile time
Known differences
WebSharper implements a .NET API in JavaScript when it can follow .NET semantics exactly or very closely.
It doesn't when that would bloat small, readable output just for coverage, or when only a partial imitation
is possible, such as System.Type, which cannot tell apart .NET types that share
a JavaScript representation. Those cases are listed here, each with the C# or JavaScript API to use instead.
string.equality.refStrings and formattingJavaScript strings are values: two equal strings are never different references.
Instead:Compare strings with == or string.Equals.
The case
{ var a = "ab"; var b = string.Concat("a", "b"); return B(a == b) + "," + B((object)a == (object)b) + "," + B(a.Equals(b)); }true,false,truetrue,true,trueboxing.equalityTypes and datesValues are not boxed in JavaScript: two boxed equal numbers compare equal by reference too.
Instead:Compare unboxed values instead of relying on reference identity.
The case
{ object a = 1, b = 1; return B(a == b) + "," + B(a.Equals(b)) + "," + B(Equals(a, b)); }false,true,truetrue,true,truefloat.precisionNumbersfloat is a JavaScript number, so it keeps double precision instead of rounding to single.
Instead:Use double, or a Float32Array from WebSharper.JavaScript when single-precision storage matters.
The case
{ float f = 0.1f; return $"{f}|{(double)f}"; }0.1|0.100000001490116120.1|0.1array.outofrangeCollectionsArray accesses are not bounds-checked: reading past the end gives undefined instead of throwing IndexOutOfRangeException.
Instead:Check Length before indexing.
The case
{ var a = new int[2]; return $"{a[2]}"; }EXN IndexOutOfRangeundefinedexception.null.derefLanguageDereferencing null throws a JavaScript TypeError, not a NullReferenceException.
Instead:Check for null (or use ?.) instead of catching NullReferenceException.
The case
{ string s = null; return $"{s.Length}"; }EXN NullReferenceEXN Exceptiondict.insertion.orderCollectionsAfter a Remove, .NET reuses the freed slot for the next Add; that order is unspecified in .NET, and JavaScript keeps insertion order.
Instead:Sort the keys, or use SortedDictionary, when order matters.
The case
{ var d = new Dictionary<string, int> { ["b"] = 1, ["a"] = 2, ["c"] = 3 }; d.Remove("a"); d["d"] = 4; return J(d.Keys); }[b,d,c][b,c,d]generic.defaultTypes and datesGenerics are erased: default(T) inside generic code is null for value types too.
Instead:Pass the default value in, or constrain T to a class.
The case
$"{Box<int>.Default()}|{Box<string>.Default() ?? "null"}"0|nullnull|nullenum.getvaluesPattern matchingEnums are erased to numbers: a boxed or generic enum value formats as its number.
Instead:Call ToString on the statically typed enum value.
The case
J(Enum.GetValues<Color>())[Red,Green,Blue][0,5,6]list.capacity.tostringCollectionsNo runtime type names: Object.ToString on a type that does not override it does not give the .NET type name.
Instead:Override ToString, or use nameof.
The case
new List<int>().ToString()System.Collections.Generic.List`1[System.Int32]""object.tostring.defaultTypes and datesNo runtime type names: Object.ToString on a type that does not override it does not give the .NET type name.
Instead:Override ToString, or use nameof.
The case
new Plain().ToString()Conformance.Plain[object Object]gettype.nameTypes and datesNo reflection: GetType() is not available in JavaScript.
Instead:Use nameof for names, pattern matching (is) for type tests, or WebSharper.JavaScript.Object.GetPrototypeOf for the JavaScript prototype.
The case
new Dog().GetType().NameDogspan.sumCollectionsSpan<T> and stackalloc are not supported.
Instead:Use arrays, or JavaScript typed arrays from WebSharper.JavaScript.
The case
{ Span<int> s = stackalloc int[] { 1, 2, 3 }; var t = 0; foreach (var x in s) t += x; return $"{t}"; }6datetime.isoTypes and datesA DateTime has no Kind in JavaScript: the "o" format writes local time with its offset, never "Z".
Instead:Use DateTimeOffset, or Date.toISOString from WebSharper.JavaScript for a UTC timestamp.
The case
new DateTime(2024, 7, 4, 9, 3, 0, DateTimeKind.Utc).ToString("o")2024-07-04T09:03:00.0000000Z2024-07-04T11:03:00.0000000+02:00readonly.wrapperCollectionsAsReadOnly returns a snapshot, not a live wrapper: it doesn't see later changes to the list.
Instead:Call AsReadOnly again after changing the list, or pass the list as IReadOnlyList<T>.
The case
{ var l = new List<int> { 1 }; var r = l.AsReadOnly(); l.Add(2); return $"{r.Count}"; }21sorteddictionary.keys.liveCollectionsSortedDictionary.Keys and .Values are snapshots, not live views: they don't see later changes.
Instead:Read Keys/Values again after changing the dictionary.
The case
{ var d = new SortedDictionary<int, string> { [1] = "a" }; var keys = d.Keys; d[2] = "b"; return $"{keys.Count}"; }21typeof.nameTypes and datesNo reflection: System.Type is not available in JavaScript, and a partial typeof(T).Name would suggest otherwise.
Instead:Use nameof(T) for names, or WebSharper.JavaScript.Object.GetPrototypeOf for the JavaScript prototype.
The case
typeof(Dog).Name + "|" + typeof(List<int>).NameDog|List`1typeof.fullnameTypes and datesNo reflection: System.Type is not available in JavaScript, and a partial typeof(T).Name would suggest otherwise.
Instead:Use nameof(T) for names, or WebSharper.JavaScript.Object.GetPrototypeOf for the JavaScript prototype.
The case
typeof(Dog).FullName + "|" + typeof(Dog).Namespace + "|" + typeof(string).FullName + "|" + typeof(Dictionary<string, int>).NameConformance.Dog|Conformance|System.String|Dictionary`2Every case
Each row is the C# that runs and the output .NET prints; a passing case prints exactly the same in JavaScript.
Numbers50 / 51 same as .NET
- Same result as .NET:
int.overflow.wraps$"{Big() + 1}"-2147483648 - Same result as .NET:
int.multiply.wraps$"{Big() * 2}"-2 - Same result as .NET:
int.multiply.large{ int x = (1 << 28) + 1; uint u = uint.MaxValue; return $"{x * x},{u * u},{x * x * x}"; }536870913,1,805306369 - Same result as .NET:
int.division.truncates$"{-7 / 2},{7 / -2}"-3,-3 - Same result as .NET:
int.remainder.sign$"{-7 % 3},{7 % -3}"-1,1 - Same result as .NET:
int.divide.by.zero$"{1 / Zero()}"EXN DivideByZero - Same result as .NET:
int.checked.overflow$"{checked(Big() + 1)}"EXN Overflow - Same result as .NET:
uint.wraps{ uint u = 0; u--; return $"{u}"; }4294967295 - Same result as .NET:
byte.wraps{ byte b = 255; b++; return $"{b}"; }0 - Same result as .NET:
short.cast.truncates$"{unchecked((short)70000)}"4464 - Same result as .NET:
long.max$"{BigL()}"9223372036854775807 - Same result as .NET:
long.overflow.wraps$"{BigL() + 1}"-9223372036854775808 - Same result as .NET:
long.multiply$"{3_000_000_000L * 3}"9000000000 - Same result as .NET:
double.tostring$"{0.1 + 0.2}|{1.0}|{1e21}|{1.5e-7}|{double.NaN}|{1.0 / 0}"0.30000000000000004|1|1E+21|1.5E-07|NaN|Infinity - Same result as .NET:
double.to.int.truncates$"{(int)2.9},{(int)-2.9}"2,-2 - Same result as .NET:
double.to.int.nan{ double n = double.NaN; return $"{(int)n}"; }0 - Same result as .NET:
math.round.bankers$"{Math.Round(2.5)},{Math.Round(3.5)},{Math.Round(-2.5)}"2,4,-2 - Same result as .NET:
math.round.digits$"{Math.Round(1.005, 2)},{Math.Round(2.345, 2)}"1,2.35 - Same result as .NET:
math.round.awayfromzero$"{Math.Round(2.5, MidpointRounding.AwayFromZero)}"3 - Same result as .NET:
math.floor.ceiling$"{Math.Floor(-1.5)},{Math.Ceiling(-1.5)},{Math.Truncate(-1.5)}"-2,-1,-1 - Same result as .NET:
math.clamp.sign$"{Math.Clamp(15, 0, 10)},{Math.Sign(-3.2)},{Math.Abs(-4)}"10,-1,4 - Same result as .NET:
math.max.min.int$"{Math.Max(3, 7)},{Math.Min(3L, 7L)}"7,3 - Same result as .NET:
format.N2(1234567.891).ToString("N2")1,234,567.89 - Same result as .NET:
format.F3(3.14159).ToString("F3")3.142 - Same result as .NET:
format.P1(0.256).ToString("P1")25.6 % - Same result as .NET:
format.D542.ToString("D5")00042 - Same result as .NET:
format.X255.ToString("X") + "," + 255.ToString("x4")FF,00ff - Same result as .NET:
format.E212345.678.ToString("E2")1.23E+004 - Same result as .NET:
format.interp.align$"[{42,5}][{42,-5}]"[ 42][42 ] - Same result as .NET:
format.interp.spec$"{3.14159:F2}|{0.5:P0}|{1234:N0}"3.14|50 %|1,234 - Same result as .NET:
format.custom(1234.5).ToString("0,0.00") + "|" + (0.5).ToString("#.##")1,234.50|.5 - Same result as .NET:
string.formatstring.Format("{0}-{1:F1}-{0}", 1, 2.25)1-2.2-1 - Same result as .NET:
parse.int$"{int.Parse("42")},{int.Parse(" -7 ")}"42,-7 - Same result as .NET:
parse.int.invalid$"{int.Parse("4x2")}"EXN Format - Same result as .NET:
parse.int.overflow$"{int.Parse("99999999999")}"EXN Overflow - Same result as .NET:
tryparse.int{ var ok = int.TryParse("12a", out var v); return $"{B(ok)},{v}"; }false,0 - Same result as .NET:
parse.double$"{double.Parse("1.5e3", CultureInfo.InvariantCulture)}"1500 - Same result as .NET:
tryparse.double{ var ok = double.TryParse("abc", out var v); return $"{B(ok)},{v}"; }false,0 - Same result as .NET:
convert.toint32.rounds$"{Convert.ToInt32(2.5)},{Convert.ToInt32(3.5)}"2,4 - Same result as .NET:
int.tostring.negative.zero$"{-0.0}"-0 - Same result as .NET:
char.arith{ char c = 'a'; c++; return $"{c},{(int)'A'},{(char)66}"; }b,65,B - Same result as .NET:
char.isdigit.letter$"{B(char.IsDigit('7'))},{B(char.IsLetter('7'))},{B(char.IsWhiteSpace('\t'))},{B(char.IsUpper('Q'))}"true,false,true,true - Same result as .NET:
bitwise.shift$"{1 << 33},{-16 >> 2},{-16 >>> 2},{1L << 40}"2,-4,1073741820,1099511627776 - Same result as .NET:
bitwise.ops$"{6 & 3},{6 | 3},{6 ^ 3},{~5}"2,7,5,-6 - Same result as .NET:
compound.assign.ops{ int x = 10; x += 5; x *= 2; x -= 3; x /= 4; x %= 4; x <<= 2; return $"{x}"; }8 - Same result as .NET:
nullable.arith{ int? a = null; int? b = 3; return $"{a + b}|{(a ?? 0) + b}|{B((a + b).HasValue)}"; }|3|false - Same result as .NET:
nullable.compare{ int? a = null; return $"{B(a < 3)},{B(a == null)},{B(a >= 3)}"; }false,true,false - Same result as .NET:
int.minvalue.negate{ int m = int.MinValue; return $"{-m}"; }-2147483648 - Same result as .NET:
double.equality.nan$"{B(double.NaN == double.NaN)},{B(double.NaN.Equals(double.NaN))}"false,true - Known difference:
float.precision{ float f = 0.1f; return $"{f}|{(double)f}"; }.NET0.1|0.10000000149011612JS0.1|0.1 - Same result as .NET:
int.compareto$"{3.CompareTo(5)},{5.CompareTo(5)}," + "b".CompareTo("a")-1,0,1
Strings and formatting47 / 48 same as .NET
- Same result as .NET:
split.basicJ("a,b,,c".Split(','))[a,b,,c] - Same result as .NET:
split.removeemptyJ("a,b,,c".Split(',', StringSplitOptions.RemoveEmptyEntries))[a,b,c] - Same result as .NET:
split.trimentriesJ(" a , b ,c ".Split(',', StringSplitOptions.TrimEntries))[a,b,c] - Same result as .NET:
split.charsJ("a b;c".Split(new[] { ' ', ';' }))[a,b,c] - Same result as .NET:
split.stringJ("a::b::c".Split("::"))[a,b,c] - Same result as .NET:
split.countJ("a,b,c,d".Split(',', 2))[a,b,c,d] - Same result as .NET:
trim.chars"xxhixx".Trim('x') + "|" + " hi ".TrimStart() + "|" + " hi ".TrimEnd() + "|"hi|hi | hi| - Same result as .NET:
pad"7".PadLeft(3, '0') + "|" + "ab".PadRight(4) + "|"007|ab | - Same result as .NET:
substring"hello".Substring(1, 3) + "|" + "hello".Substring(2)ell|llo - Same result as .NET:
substring.outofrange"hello".Substring(3, 5)EXN ArgumentOutOfRange - Same result as .NET:
indexof$"{"hello".IndexOf('l')},{"hello".LastIndexOf('l')},{"hello".IndexOf("lo")},{"hello".IndexOf('z')}"2,3,3,-1 - Same result as .NET:
indexof.startindex$"{"abcabc".IndexOf('b', 2)}"4 - Same result as .NET:
contains.comparisonB("Hello".Contains("hell", StringComparison.OrdinalIgnoreCase))true - Same result as .NET:
startswith.endswith$"{B("Hello".StartsWith("He"))},{B("Hello".EndsWith("LO", StringComparison.OrdinalIgnoreCase))}"true,true - Same result as .NET:
equals.ignorecaseB(string.Equals("abc", "ABC", StringComparison.OrdinalIgnoreCase))true - Same result as .NET:
compare.ordinal$"{Math.Sign(string.CompareOrdinal("a", "B"))},{Math.Sign(string.Compare("a", "b"))}"1,-1 - Same result as .NET:
upper.lower.invariant"MiXeD".ToUpperInvariant() + "|" + "MiXeD".ToLowerInvariant()MIXED|mixed - Same result as .NET:
replace"a-b-c".Replace("-", "+") + "|" + "a-b-c".Replace('-', '_')a+b+c|a_b_c - Same result as .NET:
insert.remove"hello".Insert(2, "XX") + "|" + "hello".Remove(1, 2) + "|" + "hello".Remove(3)heXXllo|hlo|hel - Same result as .NET:
join.concatstring.Join("-", new[] { 1, 2, 3 }) + "|" + string.Concat("a", 1, true)1-2-3|a1True - Same result as .NET:
join.nullstring.Join(",", new string[] { "a", null, "b" })a,,b - Same result as .NET:
join.concat.objectsstring.Join(",", 1, false, null, 2.5) + "|" + string.Concat(new object[] { true, null, -0.0, 7 }) + "|" + string.Concat(false, "x")1,False,,2.5|True-07|Falsex - Same result as .NET:
isnullorwhitespace$"{B(string.IsNullOrWhiteSpace(" \t"))},{B(string.IsNullOrEmpty(""))}"true,true - Same result as .NET:
char.indexer{ var s = "abc"; return $"{s[1]},{s[^1]}"; }b,c - Same result as .NET:
string.range"hello world"[6..] + "|" + "hello"[1..^1]world|ell - Same result as .NET:
string.ctor.repeatnew string('=', 5)===== - Same result as .NET:
tochararray.reversenew string("hello".ToCharArray().Reverse().ToArray())olleh - Known difference:
string.equality.ref{ var a = "ab"; var b = string.Concat("a", "b"); return B(a == b) + "," + B((object)a == (object)b) + "," + B(a.Equals(b)); }.NETtrue,false,trueJStrue,true,true - Same result as .NET:
stringbuilder{ var sb = new StringBuilder(); sb.Append("a").Append(1).AppendLine("b").Append('c'); sb.Insert(0, ">"); return sb.ToString().Replace("\n", "\\n").Replace("\r", "\\r") + "|" + sb.Length; }>a1b\nc|6 - Same result as .NET:
stringbuilder.remove.replace{ var sb = new StringBuilder("hello world"); sb.Remove(0, 6).Replace('o', '0'); return sb.ToString(); }w0rld - Same result as .NET:
interp.nested{ var xs = new[] { 1, 2 }; return $"{xs.Length} items: {string.Join(";", xs.Select(x => $"<{x}>"))}"; }2 items: <1>;<2> - Same result as .NET:
interp.null{ string s = null; object o = null; return $"[{s}][{o}]"; }[][] - Same result as .NET:
interp.adjacent.numbers{ int a = 1, b = 2; return $"{a}{b}"; }12 - Same result as .NET:
interp.single.number.is.string{ object o = $"{7}"; return B(o is string); }true - Same result as .NET:
interp.bool$"{true}|{false}"True|False - Same result as .NET:
raw.literal"""a "quoted" {x}"""a "quoted" {x} - Same result as .NET:
verbatim@"c:\path\""q"""c:\path\"q" - Same result as .NET:
escape.unicode"\u00e9\t|".Length.ToString()3 - Same result as .NET:
char.tostring.concat'a' + "b" + 'c'abc - Same result as .NET:
char.plus.char$"{'a' + 'b'}"195 - Same result as .NET:
format.string.bracesstring.Format("{{{0}}}", 5){5} - Same result as .NET:
string.compareto.culture$"{Math.Sign("apple".CompareTo("Banana"))}"1 - Same result as .NET:
tostring.object.null{ object o = null; return o?.ToString() ?? "null"; }null - Same result as .NET:
string.split.empty$"{"".Split(',').Length}"1 - Same result as .NET:
trim.unicode.ws$"[{"\u00a0x\u00a0".Trim()}]"[x] - Same result as .NET:
lastindexof.string$"{"a.b.c".LastIndexOf(".")}"3 - Same result as .NET:
string.contains.charB("abc".Contains('b'))true - Same result as .NET:
string.equals.null{ string s = null; return B(s == null) + "," + B("a" != null); }true,true
Collections46 / 52 same as .NET
- Same result as .NET:
list.ops{ var l = new List<int> { 3, 1, 2 }; l.Add(5); l.Insert(0, 9); l.Remove(1); l.RemoveAt(1); return J(l) + l.Count; }[9,2,5]3 - Same result as .NET:
list.sort.default{ var l = new List<int> { 10, 9, 1, 100 }; l.Sort(); return J(l); }[1,9,10,100] - Same result as .NET:
list.sort.strings{ var l = new List<string> { "b", "B", "a", "A" }; l.Sort(StringComparer.Ordinal); return J(l); }[A,B,a,b] - Same result as .NET:
list.sort.comparison{ var l = new List<int> { 1, 3, 2 }; l.Sort((a, b) => b.CompareTo(a)); return J(l); }[3,2,1] - Same result as .NET:
list.removeall.findindex{ var l = new List<int> { 1, 2, 3, 4, 5 }; var n = l.RemoveAll(x => x % 2 == 0); return $"{n},{J(l)},{l.FindIndex(x => x > 1)}"; }2,[1,3,5],1 - Same result as .NET:
list.indexer.outofrange{ var l = new List<int> { 1 }; return $"{l[5]}"; }EXN ArgumentOutOfRange - Same result as .NET:
list.getrange.reverse{ var l = new List<int> { 1, 2, 3, 4 }; l.Reverse(); return J(l.GetRange(1, 2)); }[3,2] - Same result as .NET:
list.binarysearch$"{new List<int> { 1, 3, 5, 7 }.BinarySearch(5)},{new List<int> { 1, 3, 5, 7 }.BinarySearch(4)}"2,-3 - Same result as .NET:
list.modify.during.foreach{ var l = new List<int> { 1, 2 }; foreach (var x in l) l.Add(x); return "no exn"; }EXN InvalidOperation - Known difference:
array.outofrange{ var a = new int[2]; return $"{a[2]}"; }.NETEXN IndexOutOfRangeJSundefined - Same result as .NET:
array.default.valuesJ(new int[3]) + "|" + J(new string[2].Select(s => s ?? "null")) + "|" + J(new bool[2].Select(B))[0,0,0]|[null,null]|[false,false] - Same result as .NET:
array.sort.reverse{ var a = new[] { 3, 1, 2 }; Array.Sort(a); Array.Reverse(a); return J(a); }[3,2,1] - Same result as .NET:
array.resize.copy{ var a = new[] { 1, 2 }; Array.Resize(ref a, 4); var b = new int[4]; Array.Copy(a, b, 2); return J(a) + J(b); }[1,2,0,0][1,2,0,0] - Same result as .NET:
array.2d{ var m = new int[2, 3]; m[1, 2] = 5; return $"{m.GetLength(0)},{m.GetLength(1)},{m[1, 2]},{m.Length}"; }2,3,5,6 - Same result as .NET:
array.2d.init{ var m = new[,] { { 1, 2, 3 }, { 4, 5, 6 } }; m[0, 1] += 10; return $"{m.Rank},{m.GetLength(0)},{m.GetLength(1)},{m.Length},{m[0, 1]},{m[1, 2]},{m.GetUpperBound(1)}"; }2,2,3,6,12,6,2 - Same result as .NET:
array.2d.defaults{ var s = new string[2, 2]; var b = new bool[1, 2]; return $"{B(s[1, 1] == null)},{B(b[0, 1])}"; }true,false - Same result as .NET:
array.2d.declaration{ int[,] m = { { 1, 2 }, { 3, 4 } }; var n = new int[2, 2] { { 5, 6 }, { 7, 8 } }; return $"{m.GetLength(1)},{m[1, 0]},{n.Length},{n[1, 1]}"; }2,3,4,8 - Same result as .NET:
array.jagged{ var j = new int[2][]; j[0] = new[] { 1 }; j[1] = new[] { 2, 3 }; return $"{j[1][1]},{j.Sum(r => r.Length)}"; }3,3 - Same result as .NET:
array.equality.refB(new[] { 1 }.Equals(new[] { 1 })) + "," + B(new[] { 1 }.SequenceEqual(new[] { 1 }))false,true - Same result as .NET:
array.fill.indexof{ var a = new int[3]; Array.Fill(a, 7); return $"{J(a)},{Array.IndexOf(a, 7)},{Array.IndexOf(a, 8)}"; }[7,7,7],0,-1 - Same result as .NET:
array.range.sliceJ(new[] { 1, 2, 3, 4, 5 }[1..^1]) + J(new[] { 1, 2, 3 }[^2..])[2,3,4][2,3] - Same result as .NET:
array.covariance{ object[] o = new string[] { "a" }; return $"{o[0]}"; }a - Known difference:
dict.insertion.order{ var d = new Dictionary<string, int> { ["b"] = 1, ["a"] = 2, ["c"] = 3 }; d.Remove("a"); d["d"] = 4; return J(d.Keys); }.NET[b,d,c]JS[b,c,d] - Same result as .NET:
dict.int.keys.order{ var d = new Dictionary<int, string> { [10] = "a", [2] = "b", [1] = "c" }; return J(d.Keys); }[10,2,1] - Same result as .NET:
dict.negative.keys.order{ var d = new Dictionary<int, int> { [5] = 0, [-3] = 0, [0] = 0, [-1] = 0 }; return J(d.Keys) + J(new HashSet<int> { 9, -2, 4 }); }[5,-3,0,-1][9,-2,4] - Same result as .NET:
dict.trygetvalue.defaults{ var d = new Dictionary<string, bool>(); var e = new Dictionary<string, double>(); d.TryGetValue("x", out var b); e.TryGetValue("x", out var x); return $"{B(b)},{x}"; }false,0 - Same result as .NET:
dict.comparer.ordinal{ var d = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase) { ["a"] = 1 }; d["A"] = 2; var h = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "x", "X", "y" }; return $"{d.Count},{d["a"]},{h.Count},{StringComparer.Ordinal.Compare("a", "B")},{StringComparer.OrdinalIgnoreCase.Equals("ab", "AB")}"; }1,2,2,31,True - Same result as .NET:
sorteddictionary.ops{ var d = new SortedDictionary<int, string>(Comparer<int>.Create((a, b) => b.CompareTo(a))) { [1] = "a", [3] = "c", [2] = "b" }; d.Remove(3); return J(d.Keys) + J(d.Values) + $"{d.Count},{B(d.ContainsKey(2))},{B(d.TryGetValue(9, out var v))}"; }[2,1][b,a]2,true,false - Known difference:
sorteddictionary.keys.live{ var d = new SortedDictionary<int, string> { [1] = "a" }; var keys = d.Keys; d[2] = "b"; return $"{keys.Count}"; }.NET2JS1 - Same result as .NET:
sortedset.ops{ var s = new SortedSet<string> { "pear", "apple", "fig" }; s.Remove("fig"); return J(s) + $"{s.Min},{s.Max},{B(s.Add("apple"))},{s.Count}"; }[apple,pear]apple,pear,false,2 - Same result as .NET:
dict.missing.keynew Dictionary<string, int>()["x"].ToString()EXN KeyNotFound - Same result as .NET:
dict.add.duplicate{ var d = new Dictionary<string, int>(); d.Add("a", 1); d.Add("a", 2); return "no exn"; }EXN Argument - Same result as .NET:
dict.trygetvalue{ var d = new Dictionary<string, int> { ["a"] = 1 }; var ok = d.TryGetValue("b", out var v); return $"{B(ok)},{v},{B(d.ContainsKey("a"))}"; }false,0,true - Same result as .NET:
dict.kvp.tostringnew Dictionary<string, int> { ["a"] = 1 }.First().ToString()[a, 1] - Same result as .NET:
dict.tryadd.getordefault{ var d = new Dictionary<string, int>(); d.TryAdd("a", 1); var b = d.TryAdd("a", 2); return $"{B(b)},{d["a"]},{d.GetValueOrDefault("z", 9)}"; }false,1,9 - Same result as .NET:
dict.comparer.ignorecase{ var d = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase) { ["Key"] = 1 }; return B(d.ContainsKey("KEY")); }true - Same result as .NET:
dict.tuple.key{ var d = new Dictionary<(int, string), int> { [(1, "a")] = 5 }; return $"{d[(1, "a")]}"; }5 - Same result as .NET:
hashset.ops{ var s = new HashSet<int> { 1, 2, 3 }; s.IntersectWith(new[] { 2, 3, 4 }); s.UnionWith(new[] { 9 }); return J(s.OrderBy(x => x)) + B(s.Add(2)); }[2,3,9]false - Same result as .NET:
hashset.string.orderJ(new HashSet<string> { "z", "a", "m" })[z,a,m] - Same result as .NET:
stack.queue{ var s = new Stack<int>(); s.Push(1); s.Push(2); var q = new Queue<int>(); q.Enqueue(1); q.Enqueue(2); return $"{s.Pop()},{s.Peek()},{q.Dequeue()},{q.Count},{J(new Stack<int>(new[] { 1, 2, 3 }))}"; }2,1,1,1,[3,2,1] - Same result as .NET:
stack.pop.empty$"{new Stack<int>().Pop()}"EXN InvalidOperation - Same result as .NET:
sorteddictionary{ var d = new SortedDictionary<string, int> { ["b"] = 1, ["a"] = 2 }; return J(d.Keys); }[a,b] - Same result as .NET:
sortedsetJ(new SortedSet<int> { 5, 1, 3, 1 })[1,3,5] - Same result as .NET:
linkedlist{ var l = new LinkedList<int>(); l.AddLast(2); l.AddFirst(1); l.AddLast(3); return J(l) + l.First.Value; }[1,2,3]1 - Same result as .NET:
collection.expression{ int[] a = [1, 2, 3]; List<int> l = [.. a, 4]; return J(l); }[1,2,3,4] - Known difference:
span.sum{ Span<int> s = stackalloc int[] { 1, 2, 3 }; var t = 0; foreach (var x in s) t += x; return $"{t}"; }.NET6JScompile error: not supported - Known difference:
readonly.wrapper{ var l = new List<int> { 1 }; var r = l.AsReadOnly(); l.Add(2); return $"{r.Count}"; }.NET2JS1 - Known difference:
list.capacity.tostringnew List<int>().ToString().NETSystem.Collections.Generic.List`1[System.Int32]JS"" - Same result as .NET:
tuple.tostring(1, "a", true).ToString() + "|" + Tuple.Create(1, 2).ToString()(1, a, True)|(1, 2) - Same result as .NET:
tuple.equalityB((1, "a") == (1, "a")) + "," + B((1, "a").Equals((1, "b")))true,false - Same result as .NET:
tuple.named{ var t = (Name: "x", Age: 3); var (n, a) = t; return $"{t.Name},{t.Item2},{n},{a}"; }x,3,x,3 - Same result as .NET:
tuple.swap{ int a = 1, b = 2; (a, b) = (b, a); return $"{a},{b}"; }2,1
LINQ48 / 48 same as .NET
- Same result as .NET:
linq.where.selectJ(Enumerable.Range(1, 10).Where(x => x % 3 == 0).Select(x => x * x))[9,36,81] - Same result as .NET:
linq.select.indexJ(new[] { "a", "b" }.Select((s, i) => $"{i},{s}"))[0,a,1,b] - Same result as .NET:
linq.orderby.stableJ(new[] { "bb", "a", "cc", "d", "ee" }.OrderBy(s => s.Length))[a,d,bb,cc,ee] - Same result as .NET:
linq.orderby.thenbyJ(new[] { (2, "b"), (1, "z"), (2, "a"), (1, "a") }.OrderBy(t => t.Item1).ThenByDescending(t => t.Item2).Select(t => $"{t.Item1},{t.Item2}"))[1,z,1,a,2,b,2,a] - Same result as .NET:
linq.orderby.strings.cultureJ(new[] { "b", "B", "a", "A", "_" }.OrderBy(s => s))[A,B,_,a,b] - Same result as .NET:
linq.orderJ(new[] { 3, 1, 2 }.Order())[1,2,3] - Same result as .NET:
linq.groupbyJ(new[] { 1, 2, 3, 4, 5 }.GroupBy(x => x % 2).Select(g => $"{g.Key}:{J(g)}"))[1:[1,3,5],0:[2,4]] - Same result as .NET:
linq.groupby.resultselectorJ(new[] { "ab", "c", "de" }.GroupBy(s => s.Length, (k, g) => $"{k}={g.Count()}"))[2=2,1=1] - Same result as .NET:
linq.tolookup{ var l = new[] { "ab", "c", "de" }.ToLookup(s => s.Length); return $"{l[2].Count()},{l[9].Count()},{l.Count}"; }2,0,2 - Same result as .NET:
linq.tolookup.order{ var l = new[] { "bb", "a", "cc", "d" }.ToLookup(s => s.Length, s => s.ToUpper()); return string.Join("|", l.Select(g => $"{g.Key}:{J(g)}")) + "," + B(l.Contains(2)); }2:[BB,CC]|1:[A,D],true - Same result as .NET:
linq.take.range.fromendJ(Enumerable.Range(1, 5).Take(^2..)) + J(new[] { 1, 2 }.Take(1..9)) + J(new[] { 1, 2 }.Take(3..1))[4,5][2][] - Same result as .NET:
linq.todictionary.dup$"{new[] { 1, 1 }.ToDictionary(x => x).Count}"EXN Argument - Same result as .NET:
linq.first.empty$"{new int[0].First()}"EXN InvalidOperation - Same result as .NET:
linq.firstordefault$"{new int[0].FirstOrDefault()},{new string[0].FirstOrDefault() ?? "null"},{new[] { 1, 2 }.FirstOrDefault(x => x > 5, -1)}"0,null,-1 - Same result as .NET:
linq.single.many$"{new[] { 1, 2 }.Single()}"EXN InvalidOperation - Same result as .NET:
linq.last.elementat$"{new[] { 1, 2, 3 }.Last()},{new[] { 1, 2, 3 }.ElementAt(1)},{new[] { 1 }.ElementAtOrDefault(5)}"3,2,0 - Same result as .NET:
linq.aggregate$"{Enumerable.Range(1, 5).Aggregate((a, b) => a * b)},{new[] { "a", "b" }.Aggregate("x", (acc, s) => acc + s, r => r.ToUpper())}"120,XAB - Same result as .NET:
linq.sum.average$"{new[] { 1, 2, 3, 4 }.Average()},{new[] { 1.5, 2.5 }.Sum()},{new[] { 2, 4 }.Average(x => x * 1.0)}"2.5,4,3 - Same result as .NET:
linq.average.empty$"{new int[0].Average()}"EXN InvalidOperation - Same result as .NET:
linq.sum.overflow$"{new[] { int.MaxValue, 1 }.Sum()}"EXN Overflow - Same result as .NET:
linq.min.max$"{new[] { 3, 1, 2 }.Min()},{new[] { 3, 1, 2 }.Max()},{new[] { "bb", "a" }.MaxBy(s => s.Length)},{new[] { "bb", "a" }.MinBy(s => s.Length)}"1,3,bb,a - Same result as .NET:
linq.min.empty$"{new int[0].Min()}"EXN InvalidOperation - Same result as .NET:
linq.distinctby.unionbyJ(new[] { "a", "A", "b" }.DistinctBy(s => s.ToLower())) + J(new[] { 1, 2 }.Union(new[] { 2, 3 }))[a,b][1,2,3] - Same result as .NET:
linq.except.intersectJ(new[] { 1, 2, 3, 2 }.Except(new[] { 2 })) + J(new[] { 1, 2, 3 }.Intersect(new[] { 3, 2 }))[1,3][2,3] - Same result as .NET:
linq.zipJ(new[] { 1, 2, 3 }.Zip(new[] { "a", "b" }, (n, s) => $"{n},{s}")) + J(new[] { 1, 2 }.Zip(new[] { 'x', 'y' }).Select(t => $"{t.First},{t.Second}"))[1,a,2,b][1,x,2,y] - Same result as .NET:
linq.skip.takeJ(Enumerable.Range(1, 10).Skip(2).Take(3)) + J(Enumerable.Range(1, 5).SkipWhile(x => x < 3).TakeWhile(x => x < 5)) + J(Enumerable.Range(1, 5).TakeLast(2)) + J(Enumerable.Range(1, 5).SkipLast(3))[3,4,5][3,4][4,5][1,2] - Same result as .NET:
linq.take.rangeJ(Enumerable.Range(1, 10).Take(2..4))[3,4] - Same result as .NET:
linq.chunkJ(Enumerable.Range(1, 5).Chunk(2).Select(c => J(c)))[[1,2],[3,4],[5]] - Same result as .NET:
linq.selectmanyJ(new[] { "ab", "cd" }.SelectMany(s => s.ToCharArray()))[a,b,c,d] - Same result as .NET:
linq.joinJ(new[] { (1, "a"), (2, "b") }.Join(new[] { (2, "x"), (1, "y"), (1, "z") }, l => l.Item1, r => r.Item1, (l, r) => l.Item2 + r.Item2))[ay,az,bx] - Same result as .NET:
linq.groupjoinJ(new[] { 1, 2 }.GroupJoin(new[] { 1, 1, 3 }, a => a, b => b, (a, bs) => $"{a}:{bs.Count()}"))[1:2,2:0] - Same result as .NET:
linq.any.all.contains$"{B(new int[0].All(x => x > 0))},{B(new[] { 1 }.Any())},{B(new[] { 1, 2 }.Contains(2))}"true,true,true - Same result as .NET:
linq.count.predicate$"{Enumerable.Range(1, 10).Count(x => x > 7)},{new[] { 1 }.LongCount()}"3,1 - Same result as .NET:
linq.repeat.empty.concatJ(Enumerable.Repeat("x", 3).Concat(Enumerable.Empty<string>()).Append("y").Prepend("w"))[w,x,x,x,y] - Same result as .NET:
linq.reverse.defaultifemptyJ(new[] { 1, 2 }.Reverse()) + J(new int[0].DefaultIfEmpty(7))[2,1][7] - Same result as .NET:
linq.sequenceequalB(new[] { 1, 2 }.SequenceEqual(new List<int> { 1, 2 }))true - Same result as .NET:
linq.cast.oftypeJ(new object[] { 1, "a", 2, null }.OfType<int>()) + J(new object[] { "a", "b" }.Cast<string>())[1,2][a,b] - Same result as .NET:
linq.cast.invalidJ(new object[] { 1, "a" }.Cast<int>())EXN InvalidCast - Same result as .NET:
linq.cast.validJ(new object[] { "a", null, "b" }.Cast<string>().Select(s => s ?? "null")) + J(new object[] { 1, 2 }.Cast<int>())[a,null,b][1,2] - Same result as .NET:
linq.sum.selector.overflow$"{new[] { 1, 2 }.Sum(x => int.MaxValue / 2 + x)}"EXN Overflow - Same result as .NET:
linq.sum.long$"{new[] { long.MaxValue - 1, 1L }.Sum()}"9223372036854775807 - Same result as .NET:
linq.deferred{ var log = new List<string>(); var q = Counted(log).Where(x => { log.Add($"w{x}"); return x % 2 == 0; }).Take(1); log.Add("built"); var r = q.ToList(); return J(log) + J(r); }[built,y1,w1,y2,w2][2] - Same result as .NET:
linq.query.syntaxJ(from x in Enumerable.Range(1, 6) let sq = x * x where sq > 5 orderby x descending select $"{x}:{sq}")[6:36,5:25,4:16,3:9] - Same result as .NET:
linq.query.groupJ(from w in new[] { "apple", "avocado", "banana" } group w by w[0] into g select $"{g.Key},{g.Count()}")[a,2,b,1] - Same result as .NET:
linq.toarray.tolist.tohashset$"{new[] { 1, 1, 2 }.ToHashSet().Count},{new[] { 1 }.ToList().Count}"2,1 - Same result as .NET:
linq.range.negativeJ(Enumerable.Range(1, -1))EXN ArgumentOutOfRange - Same result as .NET:
linq.indexJ(new[] { "a", "b" }.Index().Select(t => $"{t.Index},{t.Item}"))[0,a,1,b] - Same result as .NET:
linq.countby.aggregatebyJ(new[] { "a", "b", "a" }.CountBy(s => s).Select(kv => $"{kv.Key},{kv.Value}"))[a,2,b,1]
Language41 / 42 same as .NET
- Same result as .NET:
closure.loop.capture.for{ var fs = new List<Func<int>>(); for (int i = 0; i < 3; i++) fs.Add(() => i); return J(fs.Select(f => f())); }[3,3,3] - Same result as .NET:
closure.loop.capture.foreach{ var fs = new List<Func<int>>(); foreach (var i in new[] { 0, 1, 2 }) fs.Add(() => i); return J(fs.Select(f => f())); }[0,1,2] - Same result as .NET:
closure.mutation{ int x = 1; Action inc = () => x++; inc(); inc(); return $"{x}"; }3 - Same result as .NET:
local.function.recursive{ int Fact(int n) => n <= 1 ? 1 : n * Fact(n - 1); return $"{Fact(10)}"; }3628800 - Same result as .NET:
static.local.function{ static int Sq(int n) => n * n; return $"{Sq(7)}"; }49 - Same result as .NET:
optional.named.argsOpt(1) + "|" + Opt(1, c: "z") + "|" + Names(last: "L")1,2,c|1,2,z|fL - Same result as .NET:
params$"{Sum()},{Sum(1, 2, 3)},{Sum(new[] { 4, 5 })}"0,6,9 - Same result as .NET:
out.ref{ int b = 3; Out(out var a, ref b); return $"{a},{b}"; }5,6 - Same result as .NET:
ref.local{ var arr = new[] { 1, 2 }; ref int r = ref arr[1]; r = 9; return J(arr); }[1,9] - Same result as .NET:
iterator.lazy.infiniteJ(Fib().Skip(10).Take(3))[55,89,144] - Same result as .NET:
iterator.finally.on.dispose{ var log = new List<string>(); foreach (var s in WithFinally(log)) { log.Add(s); break; } return J(log); }[a,finally] - Same result as .NET:
iterator.yield.breakJ(YieldBreak(3))[0,1,2] - Same result as .NET:
iterator.reenumerate{ var e = YieldBreak(2); return J(e) + J(e); }[0,1][0,1] - Same result as .NET:
exception.custom{ try { throw new CustomException("boom", 42); } catch (CustomException e) { return $"{e.Message},{e.Code}"; } }boom,42 - Same result as .NET:
exception.message{ try { throw new InvalidOperationException("bad op"); } catch (Exception e) { return e.Message; } }bad op - Same result as .NET:
exception.filter{ try { throw new CustomException("x", 2); } catch (CustomException e) when (e.Code == 1) { return "one"; } catch (CustomException e) when (e.Code == 2) { return "two"; } }two - Same result as .NET:
exception.finally.order{ var log = new List<string>(); try { try { log.Add("try"); throw new Exception("e"); } finally { log.Add("finally"); } } catch { log.Add("catch"); } return J(log); }[try,finally,catch] - Same result as .NET:
exception.rethrow{ try { try { throw new ArgumentException("inner"); } catch (Exception) { throw; } } catch (ArgumentException e) { return e.Message; } }inner - Same result as .NET:
exception.inner{ var e = new Exception("outer", new Exception("inner")); return e.InnerException.Message; }inner - Known difference:
exception.null.deref{ string s = null; return $"{s.Length}"; }.NETEXN NullReferenceJSEXN Exception - Same result as .NET:
exception.tostring.prefixnew InvalidOperationException("m").Messagem - Same result as .NET:
using.dispose.order{ var log = new List<string>(); using (var a = new Disp(log, "a")) using (var b = new Disp(log, "b")) { log.Add("body"); } return J(log); }[body,dispose b,dispose a] - Same result as .NET:
using.declaration{ var log = new List<string>(); void Run() { using var a = new Disp(log, "a"); log.Add("body"); } Run(); return J(log); }[body,dispose a] - Same result as .NET:
events{ var c = new Counter(); var log = new List<int>(); Action<int> h = v => log.Add(v); c.Changed += h; c.Inc(); c.Changed -= h; c.Inc(); return J(log) + c.Value; }[1]2 - Same result as .NET:
operator.overload.implicit{ var c = new Counter(); c += 3; int v = c; return $"{v},{c[2]}"; }3,6 - Same result as .NET:
static.field{ Counter.Instances = 0; new Counter(); new Counter(); return $"{Counter.Instances}"; }2 - Same result as .NET:
delegate.multicast{ var log = new List<string>(); Action a = () => log.Add("1"); a += () => log.Add("2"); a(); return J(log); }[1,2] - Same result as .NET:
delegate.multicast.return{ Func<int> f = () => 1; f += () => 2; return $"{f()}"; }2 - Same result as .NET:
func.compose{ Func<int, int> inc = x => x + 1; Func<int, int> dbl = x => x * 2; Func<int, int> both = x => dbl(inc(x)); return $"{both(3)}"; }8 - Same result as .NET:
struct.copy.semantics{ var a = new MutPoint(); var b = a; b.Move(); var arr = new[] { a }; arr[0].Move(); var list = new List<MutPoint> { a }; var l0 = list[0]; l0.Move(); return $"{a.X},{b.X},{arr[0].X},{list[0].X}"; }0,1,1,0 - Same result as .NET:
struct.default.equalityB(new MutPoint().Equals(new MutPoint())) + "," + B(new MutPoint { X = 1 }.Equals(new MutPoint()))true,false - Same result as .NET:
null.conditional{ Counter c = null; int? v = c?.Value; string s = null; return $"{v?.ToString() ?? "none"},{s?.Length ?? -1}"; }none,-1 - Same result as .NET:
null.coalescing.assign{ List<int> l = null; l ??= new List<int>(); l.Add(1); string s = null; s ??= "d"; return $"{l.Count},{s}"; }1,d - Same result as .NET:
conditional.chain{ int x = 5; return x > 3 ? x > 4 ? "big" : "mid" : "small"; }big - Same result as .NET:
goto.labels{ int i = 0; again: i++; if (i < 3) goto again; return $"{i}"; }3 - Same result as .NET:
while.dowhile.continue{ var r = ""; int i = 0; do { i++; if (i == 2) continue; r += i; } while (i < 4); while (i > 0) { i--; if (i == 1) break; } return r + i; }1341 - Same result as .NET:
lazy{ var n = 0; var l = new Lazy<int>(() => ++n); var a = l.Value; var b = l.Value; return $"{a},{b},{n},{B(l.IsValueCreated)}"; }1,1,1,true - Same result as .NET:
default.literal{ int i = default; string s = default; return $"{i},{s ?? "null"}"; }0,null - Same result as .NET:
nameofnameof(Counter.Value) + nameof(Language)ValueLanguage - Same result as .NET:
checked.unchecked.block{ int m = int.MaxValue; int r = unchecked(m + 1); return $"{r}"; }-2147483648 - Same result as .NET:
discard.assign{ _ = int.TryParse("5", out var v); return $"{v}"; }5 - Same result as .NET:
lambda.static.default.params{ var f = (int a, int b = 10) => a + b; return $"{f(1)},{f(1, 2)}"; }11,3
Pattern matching24 / 25 same as .NET
- Same result as .NET:
switch.type.patternsstring.Join("|", new object[] { null, -1, 3, "", "x", new Point(0, 0), new Point(2, 2), new Point(1, 3), new[] { 7, 8, 9 }, 1.5 }.Select2(Classify))null|negative int|int 3|empty string|string x|origin|diagonal 2|point 1|long array 7|other - Same result as .NET:
switch.property.positional$"{Area(new Circle(1))},{Area(new Rect(2, 3))}"3.14,6 - Same result as .NET:
switch.throw.arm$"{Area(null)}"EXN Argument - Same result as .NET:
switch.relationalstring.Join(",", new[] { 95, 85, 50, -1, 101 }.Select2(Grade))A,B,C,invalid,A - Same result as .NET:
switch.list.patternsstring.Join("|", new[] { new int[0], new[] { 1 }, new[] { 1, 2 }, new[] { 1, 2, 3, 4 } }.Select2(ListPat))empty|one 1|two 1,2|many 1..4 - Same result as .NET:
switch.list.sliceSliceLen(new[] { 1, 2, 3, 4, 5 }) + "," + SliceLen(new[] { 1 })3,short - Same result as .NET:
switch.tuple$"{Tuple(0, true)},{Tuple(5, true)},{Tuple(20, false)},{Tuple(3, false)}"zero,flag,big,rest - Same result as .NET:
switch.nomatch{ int x = 7; var r = x switch { 1 => "one", 2 => "two" }; return r; }EXN InvalidOperation - Same result as .NET:
is.not.null{ object o = "s"; return B(o is not null) + "," + B(o is string { Length: 1 }); }true,true - Same result as .NET:
is.type.var{ object o = 42; if (o is int n && n > 40) return $"{n + 1}"; return "no"; }43 - Same result as .NET:
as.cast{ object o = "x"; var s = o as string; var p = o as Point; return $"{s}|{(p == null ? "null" : "p")}"; }x|null - Same result as .NET:
cast.invalid{ object o = "x"; var p = (Point)o; return p.ToString(); }EXN InvalidCast - Same result as .NET:
cast.valid{ object o = new Dog(); Animal a = (Animal)o; object n = null; var d = (Dog)n; return a.Sound() + "," + B(d == null); }woof,true - Same result as .NET:
unbox.invalid{ object o = "a"; return $"{(int)o}"; }EXN InvalidCast - Same result as .NET:
unbox.valid{ object o = 5, b = true; return $"{(int)o},{(bool)b}"; }5,True - Same result as .NET:
reference.equality.class{ var a = new Dog(); Animal b = a; object c = new Dog(); return B(a == b) + "," + B(a != c) + "," + B((object)null == null); }true,true,true - Same result as .NET:
switch.statement.goto{ var r = ""; for (int i = 0; i < 4; i++) { switch (i) { case 0: case 1: r += "a"; break; case 2: r += "b"; break; default: r += "c"; break; } } return r; }aabc - Same result as .NET:
switch.string{ string s = "two"; switch (s) { case "one": return "1"; case "two": return "2"; default: return "?"; } }2 - Same result as .NET:
enum.tostring$"{Color.Green}|{(Color)6}|{(int)Color.Blue}|{(Color)42}"Green|Blue|6|42 - Same result as .NET:
enum.flags.tostring$"{Perm.Read | Perm.Write}|{Perm.None}"Read, Write|None - Same result as .NET:
enum.hasflagB((Perm.Read | Perm.Exec).HasFlag(Perm.Exec)) + "," + B((Perm.Read).HasFlag(Perm.Write))true,false - Same result as .NET:
enum.parse$"{Enum.Parse<Color>("Blue")}|{(int)Enum.Parse<Color>("Green")}"Blue|5 - Same result as .NET:
enum.tryparse{ var ok = Enum.TryParse<Color>("Purple", out var c); return $"{B(ok)},{c}"; }false,Red - Known difference:
enum.getvaluesJ(Enum.GetValues<Color>()).NET[Red,Green,Blue]JS[0,5,6] - Same result as .NET:
enum.switchColor.Blue switch { Color.Red => "r", Color.Blue => "b", _ => "?" }b
Records and structs29 / 29 same as .NET
- Same result as .NET:
record.tostringnew Point(1, 2).ToString()Point { X = 1, Y = 2 } - Same result as .NET:
record.tostring.nestednew Nested(new Point(1, 2), "a").ToString()Nested { P = Point { X = 1, Y = 2 }, Label = a } - Same result as .NET:
record.tostring.derivednew Point3(1, 2, 3).ToString()Point3 { X = 1, Y = 2, Z = 3 } - Same result as .NET:
record.tostring.bodynew WithBody { A = "x", B = 2 }.ToString()WithBody { A = x, B = 2 } - Same result as .NET:
record.equalityB(new Point(1, 2) == new Point(1, 2)) + "," + B(new Point(1, 2).Equals(new Point(1, 2))) + "," + B(new Point(1, 2) != new Point(2, 1))true,true,true - Same result as .NET:
record.equality.objectB(((object)new Point(1, 2)).Equals(new Point(1, 2)))true - Same result as .NET:
record.equality.derivedB(new Point(1, 2) == new Point3(1, 2, 0))false - Same result as .NET:
record.equality.nestedB(new Nested(new Point(1, 2), "a") == new Nested(new Point(1, 2), "a"))true - Same result as .NET:
record.equality.array.member{ var t = new[] { 1 }; return B(new Tagged("a", t) == new Tagged("a", t)) + "," + B(new Tagged("a", new[] { 1 }) == new Tagged("a", new[] { 1 })); }true,false - Same result as .NET:
record.hash.equalB(new Point(1, 2).GetHashCode() == new Point(1, 2).GetHashCode())true - Same result as .NET:
record.with(new Person("Ann", 30) with { Age = 31 }).ToString()Person { Name = Ann, Age = 31, Greeting = Hi Ann } - Same result as .NET:
record.with.derived{ Point p = new Point3(1, 2, 3); var q = p with { X = 9 }; return q.ToString(); }Point3 { X = 9, Y = 2, Z = 3 } - Same result as .NET:
record.with.unchanged.original{ var a = new Person("Ann", 30); var b = a with { Name = "Bo" }; return a.Name + b.Name; }AnnBo - Same result as .NET:
record.deconstruct{ var (x, y) = new Point(3, 4); return $"{x},{y}"; }3,4 - Same result as .NET:
record.computed.membernew Person("Ann", 30).GreetingHi Ann - Same result as .NET:
record.in.hashset{ var s = new HashSet<Point> { new Point(1, 2), new Point(1, 2), new Point(2, 1) }; return $"{s.Count}"; }2 - Same result as .NET:
record.as.dict.key{ var d = new Dictionary<Point, string> { [new Point(1, 2)] = "a" }; return d[new Point(1, 2)]; }a - Same result as .NET:
record.distinct$"{new[] { new Point(1, 2), new Point(1, 2) }.Distinct().Count()}"1 - Same result as .NET:
record.groupby$"{new[] { new Point(1, 2), new Point(1, 2), new Point(0, 0) }.GroupBy(p => p).Count()}"2 - Same result as .NET:
record.struct.tostringnew Vec(1.5, 2).ToString()Vec { X = 1.5, Y = 2 } - Same result as .NET:
record.struct.equalityB(new Vec(1, 2) == new Vec(1, 2)) + "," + B(new Money("EUR", 5).Equals(new Money("EUR", 5)))true,true - Same result as .NET:
record.struct.copy{ var a = new Vec(1, 2); var b = a; b.X = 9; return $"{a.X},{b.X}"; }1,9 - Same result as .NET:
record.struct.with(new Money("EUR", 5) with { Cents = 7 }).ToString()Money { Currency = EUR, Cents = 7 } - Same result as .NET:
record.struct.defaultdefault(Vec).ToString()Vec { X = 0, Y = 0 } - Same result as .NET:
record.equals.null{ Point p = null; return B(p == null) + "," + B(new Point(1, 2).Equals(null)); }true,false - Same result as .NET:
record.reference.equalsB(ReferenceEquals(new Point(1, 2), new Point(1, 2)))false - Same result as .NET:
record.init.props{ var w = new WithBody { A = "a" }; return $"{w.A},{w.B}"; }a,0 - Same result as .NET:
record.list.containsB(new List<Point> { new Point(1, 2) }.Contains(new Point(1, 2)))true - Same result as .NET:
record.indexof$"{Array.IndexOf(new[] { new Point(0, 0), new Point(1, 2) }, new Point(1, 2))}"1
Types and dates37 / 44 same as .NET
- Same result as .NET:
interface.default.method{ IGreeter a = new Plain(), b = new Custom(); return a.Greet() + "|" + b.Greet(); }Hello plain|Yo - Same result as .NET:
virtual.dispatchnew Dog().Describe() + "|" + new Puppy().Describe()dog says woof|puppy says woof! - Same result as .NET:
new.hiding{ var h = new Hider(); Dog d = h; return h.Sound() + "|" + d.Sound(); }hidden|woof - Same result as .NET:
generic.constraintB(new Box<int>(5).Bigger(3)) + "," + B(new Box<string>("a").Bigger("b"))true,false - Known difference:
generic.default$"{Box<int>.Default()}|{Box<string>.Default() ?? "null"}".NET0|nullJSnull|null - Same result as .NET:
generic.method.max$"{Max(3, 9)},{Max("b", "a")}"9,b - Same result as .NET:
generic.tostring$"{Generic(1)},{Generic<string>(null)},{Generic(1.5)}"1,null,1.5 - Same result as .NET:
ctor.chaining.order{ Ctor.Log.Clear(); new Ctor(); return J(Ctor.Log); }[field,ctor(1),ctor()] - Same result as .NET:
required.init{ var r = new Required { Name = "n" }; return $"{r.Name},{r.Age}"; }n,18 - Same result as .NET:
primary.ctor{ var p = new PrimaryCtor("x", 1); p.Birthday(); return p.Describe(); }x/2 - Same result as .NET:
override.equalsB(new Eq { Id = 1 }.Equals(new Eq { Id = 1 })) + "," + B(new Eq { Id = 1 } == new Eq { Id = 1 }) + "," + $"{new[] { new Eq { Id = 1 }, new Eq { Id = 1 } }.Distinct().Count()}"true,false,1 - Same result as .NET:
override.equals.dictionary{ var d = new Dictionary<Eq, int> { [new Eq { Id = 3 }] = 7 }; return $"{d[new Eq { Id = 3 }]}"; }7 - Same result as .NET:
override.tostring$"{new WithToString()}|{string.Concat(new WithToString(), "")}"custom!|custom! - Known difference:
object.tostring.defaultnew Plain().ToString().NETConformance.PlainJS[object Object] - Known difference:
gettype.namenew Dog().GetType().Name.NETDogJScompile error: not supported - Known difference:
typeof.nametypeof(Dog).Name + "|" + typeof(List<int>).Name.NETDog|List`1JScompile error: not supported - Known difference:
typeof.fullnametypeof(Dog).FullName + "|" + typeof(Dog).Namespace + "|" + typeof(string).FullName + "|" + typeof(Dictionary<string, int>).Name.NETConformance.Dog|Conformance|System.String|Dictionary`2JScompile error: not supported - Same result as .NET:
is.base.interface{ object d = new Puppy(); return B(d is Animal) + B(d is IGreeter) + B(d is Dog); }truefalsetrue - Known difference:
boxing.equality{ object a = 1, b = 1; return B(a == b) + "," + B(a.Equals(b)) + "," + B(Equals(a, b)); }.NETfalse,true,trueJStrue,true,true - Same result as .NET:
boxing.int.long{ object a = 1, b = 1L; return B(a.Equals(b)); }false - Same result as .NET:
anonymous.type{ var a = new { X = 1, Y = "y" }; var b = new { X = 1, Y = "y" }; return a.ToString() + "|" + B(a.Equals(b)); }{ X = 1, Y = y }|true - Same result as .NET:
datetime.basic{ var d = new DateTime(2024, 2, 29, 13, 5, 9); return $"{d.Year}-{d.Month}-{d.Day} {d.Hour}:{d.Minute}:{d.Second} {d.DayOfWeek} {d.DayOfYear}"; }2024-2-29 13:5:9 Thursday 60 - Same result as .NET:
datetime.arith{ var d = new DateTime(2024, 1, 31); return $"{d.AddMonths(1):yyyy-MM-dd}|{d.AddDays(1):yyyy-MM-dd}|{(new DateTime(2024, 3, 1) - d).TotalDays}"; }2024-02-29|2024-02-01|30 - Same result as .NET:
datetime.formatnew DateTime(2024, 7, 4, 9, 3, 0).ToString("yyyy-MM-dd HH:mm:ss") + "|" + new DateTime(2024, 7, 4).ToString("ddd, dd MMM yyyy")2024-07-04 09:03:00|Thu, 04 Jul 2024 - Known difference:
datetime.isonew DateTime(2024, 7, 4, 9, 3, 0, DateTimeKind.Utc).ToString("o").NET2024-07-04T09:03:00.0000000ZJS2024-07-04T11:03:00.0000000+02:00 - Same result as .NET:
datetime.parseDateTime.Parse("2024-07-04T09:03:00").ToString("yyyy/MM/dd HH:mm")2024/07/04 09:03 - Same result as .NET:
timespan{ var t = TimeSpan.FromMinutes(90) + TimeSpan.FromSeconds(30); return $"{t}|{t.TotalHours}|{t.Hours}|{t.Minutes}"; }01:30:30|1.5083333333333333|1|30 - Same result as .NET:
timespan.formatTimeSpan.FromMilliseconds(3723004).ToString(@"hh\:mm\:ss\.fff")01:02:03.004 - Same result as .NET:
timespan.format.standard{ var t = new TimeSpan(1, 2, 3, 4, 50); return t.ToString("c") + "|" + t.ToString("g") + "|" + t.ToString("G") + "|" + TimeSpan.FromMinutes(5).ToString("g"); }1.02:03:04.0500000|1:2:03:04.05|1:02:03:04.0500000|0:05:00 - Same result as .NET:
timespan.format.custom{ var t = new TimeSpan(3, 4, 5, 6, 70); return t.ToString(@"d\.hh\:mm") + "|" + t.ToString("%d") + "|" + t.ToString(@"dd' days' h' h'") + "|" + t.ToString(@"ss\.FFF"); }EXN Format - Same result as .NET:
anonymous.type.nested{ var a = new { Name = (string)null, Flag = true, Inner = new { V = 1.5 } }; return $"{a}|{new { }}"; }{ Name = , Flag = True, Inner = { V = 1.5 } }|{ } - Same result as .NET:
dateonlynew DateOnly(2024, 2, 28).AddDays(2).ToString("yyyy-MM-dd")2024-03-01 - Same result as .NET:
dateonly.ops{ var d = new DateOnly(2024, 1, 31); var e = d.AddMonths(1); return $"{e.Year}-{e.Month}-{e.Day},{e.DayOfWeek},{B(d < e)},{B(new DateOnly(2024, 3, 1) == d.AddDays(30))},{d.AddYears(1):yyyy/MM/dd}"; }2024-2-29,Thursday,true,true,2025/01/31 - Same result as .NET:
dateonly.tostring$"{new DateOnly(2024, 7, 4)}|" + new DateOnly(2024, 7, 4).ToString()07/04/2024|07/04/2024 - Same result as .NET:
guid.parse.format{ var g = Guid.Parse("0f8fad5b-d9cb-469f-a165-70867728950e"); return g.ToString() + "|" + g.ToString("N") + "|" + B(g == new Guid("0F8FAD5B-D9CB-469F-A165-70867728950E")); }0f8fad5b-d9cb-469f-a165-70867728950e|0f8fad5bd9cb469fa16570867728950e|true - Same result as .NET:
guid.emptyGuid.Empty.ToString()00000000-0000-0000-0000-000000000000 - Same result as .NET:
random.seeded.range{ var r = new Random(1); var x = r.Next(10); return B(x >= 0 && x < 10); }true - Same result as .NET:
nullable.struct.getvalueordefault{ int? a = null; return $"{a.GetValueOrDefault()},{a.GetValueOrDefault(4)}"; }0,4 - Same result as .NET:
nullable.value.null{ int? a = null; return $"{a.Value}"; }EXN InvalidOperation - Same result as .NET:
convert.tostring.booltrue.ToString() + "|" + bool.Parse("TRUE")True|True - Same result as .NET:
string.gethashcode.stableB("abc".GetHashCode() == "abc".GetHashCode())true - Same result as .NET:
valuetuple.compare$"{Math.Sign((1, 2).CompareTo((1, 3)))}"-1 - Same result as .NET:
comparer.default$"{Math.Sign(Comparer<string>.Default.Compare("a", "B"))},{Math.Sign(Comparer<int>.Default.Compare(2, 1))}"1,1 - Same result as .NET:
equalitycomparer.defaultB(EqualityComparer<Point>.Default.Equals(new Point(1, 1), new Point(1, 1)))true
How this is computed
The cases live in WebSharper's own repository (tests/WebSharper.CSharp.Conformance). The same C# project is built for .NET and with WebSharper, run on .NET and under Node, and the outputs are compared. The check runs on every release build against a committed baseline, so a change that makes any case worse fails the build. The TypeScript declarations WebSharper generates for the cases are type-checked too.
- Same as .NET: JavaScript prints exactly what .NET prints.
- Known difference: an accepted difference that follows from JavaScript, listed above with its alternative.
- Mismatch: a different result with no accepted reason, a bug to fix.
For tools and AI agents
The results are published as JSON: every case with its C# source, its .NET output and its status, and the known differences with their reasons and alternatives.
Whether an API translates at all is a separate question: see API coverage.
F# conformance
F# that behaves like .NET in the browser
Every case below is a piece of F# run twice: on .NET, and as the JavaScript WebSharper compiles it to. The results are compared character by character. Where they differ, it is listed as a known difference, with what to write instead.
Same result as .NET
91.3%
514 of 563 cases
Known differences
22
where JavaScript itself differs, each with an alternative
Unexplained differences
19
silent mismatches; 8 cases rejected at compile time
Known differences
WebSharper implements a .NET API in JavaScript when it can follow .NET semantics exactly or very closely.
It doesn't when that would bloat small, readable output just for coverage, or when only a partial imitation
is possible, such as System.Type, which cannot tell apart .NET types that share
a JavaScript representation. Those cases are listed here, each with the F# or JavaScript API to use instead.
float32.arithNumbersfloat32 is a JavaScript number, so it keeps double precision instead of rounding to single.
Instead:Use float, or a Float32Array from WebSharper.JavaScript when single-precision storage matters.
The case
string (0.1f + 0.2f)0.30.30000000000000004recursion.deep.nontailLanguageJavaScript has a fixed call stack, so deep non-tail recursion overflows sooner than on .NET.
Instead:Write the function tail-recursive (WebSharper turns self tail calls into loops), or use a loop or a fold.
The case
let rec f n = if n = 0 then 0 else 1 + f (n - 1) in string (f 10000)10000EXN Exceptionstring.equalityStrings and printfJavaScript strings are values: two equal strings are never different references.
Instead:Compare strings with = or String.Equals.
The case
B (s "abc" = "a" + "bc") + "," + B (obj.ReferenceEquals(s "abc", "a" + s "bc"))true,falsetrue,trueequals.boxedRecords, unions and equalityNumbers are not boxed with their .NET type in JavaScript: box 1 and box 1.0 are the same value.
Instead:Compare unboxed values of a known type.
The case
B ((box 1).Equals(box 1)) + "," + B ((box 1).Equals(box 1L)) + "," + B (box 1 = box 1.0)true,false,falsetrue,false,truematch.typetest.float.intPattern matchingint and float are both JavaScript numbers, so :? int cannot tell a whole-number float from an int.
Instead:Keep the static type, or use a union case per numeric type.
The case
match box 2.0 with :? int -> "int" | :? float -> "float" | _ -> "?"floatintmatch.typetest.char.stringPattern matchingA char is a one-character JavaScript string, so :? string also matches a boxed char.
Instead:Keep the static type, or use a union case per type.
The case
match box 'c' with :? string -> "string" | :? char -> "char" | _ -> "?"charstringstring.index.out.of.rangeStrings and printfString indexing is not bounds-checked: reading past the end gives undefined instead of throwing IndexOutOfRangeException.
Instead:Check Length before indexing.
The case
string (s "abc").[5]EXN IndexOutOfRange<null>exception.nullrefLanguageDereferencing null throws a JavaScript TypeError, not a NullReferenceException.
Instead:Use options or check with isNull instead of catching NullReferenceException.
The case
let s : string = null in string s.LengthEXN NullReferenceEXN Exceptionoption.value.propRecords, unions and equalityNone is null, so .Value on it throws a JavaScript TypeError, not a NullReferenceException.
Instead:Match on the option, or use Option.defaultValue.
The case
string (None: int option).ValueEXN NullReferenceEXN Exceptiondictionary.union.keyMaps, sets and dictionariesNone is null, which .NET rejects as a Dictionary key; JavaScript accepts it.
Instead:Use Map, or a key type without a null case.
The case
let d = Dictionary<int option, int>() in d.[Some 1] <- 5; d.[None] <- 6; string d.[Some 1] + string d.[None]EXN ArgumentNull56datetime.format.isoDates, math and conversionsA DateTime has no Kind in JavaScript: the "o" format writes local time with its offset.
Instead:Use DateTimeOffset, or Date.toISOString from WebSharper.JavaScript for a UTC timestamp.
The case
(d ()).ToString("o")2024-02-29T13:45:30.00000002024-02-29T13:45:30.0000000+00:00decimal.addNumbersdecimal is implemented by the WebSharper.MathJS package, not by the standard library.
Instead:Reference WebSharper.MathJS to use decimal.
The case
string (0.1M + 0.2M)0.3decimal.divideNumbersdecimal is implemented by the WebSharper.MathJS package, not by the standard library.
Instead:Reference WebSharper.MathJS to use decimal.
The case
string (1M / 3M)0.3333333333333333333333333333sprintf.MStrings and printfdecimal is implemented by the WebSharper.MathJS package, not by the standard library.
Instead:Reference WebSharper.MathJS to use decimal.
The case
sprintf "%M" 1.50M1.50typeof.nameLanguageNo reflection: System.Type is not available in JavaScript, and a partial typeof<T>.Name would suggest otherwise.
Instead:Use nameof for names, or WebSharper.JavaScript.Object.GetPrototypeOf for the JavaScript prototype.
The case
typeof<int>.NameInt32typeof.int.nameDates, math and conversionsNo reflection: System.Type is not available in JavaScript, and a partial typeof<T>.Name would suggest otherwise.
Instead:Use nameof for names, or WebSharper.JavaScript.Object.GetPrototypeOf for the JavaScript prototype.
The case
typeof<string>.FullNameSystem.Stringgettype.nameDates, math and conversionsNo reflection: GetType() is not available in JavaScript.
Instead:Use nameof for names, :? patterns for type tests, or WebSharper.JavaScript.Object.GetPrototypeOf for the JavaScript prototype.
The case
(box 1).GetType().NameInt32enum.parseRecords, unions and equalityNo reflection: Enum.Parse takes a System.Type, which is not available in JavaScript.
Instead:Match the string against the enum's cases instead.
The case
string (Enum.Parse(typeof<Color>, "Blue") :?> Color)Bluechar.unicode.upperStrings and printfJavaScript upper-cases strings with full Unicode case mapping, so String.ToUpper turns "ß" into "SS" where .NET keeps "ß".
Instead:Upper-case per character with String.map Char.ToUpper, which keeps characters that have no single-character upper case.
The case
string (Char.ToUpper 'ß') + "," + (s "straße").ToUpper()ß,STRAßEß,STRASSEstring.concat.nullStrings and printf+ on strings is JavaScript string concatenation, which writes a null string as "null"; treating null as "" would add a check to every concatenation.
Instead:Pass a string that may be null through string s, which gives "" for null.
The case
s "a" + (null: string) + "b"abanullbresultRecords, unions and equalityNo runtime type names: string of a Result or Choice value is the .NET type name, which JavaScript does not have.
Instead:Match on the cases and format the value inside.
The case
let r : Result<int, string> = Ok 1 in string (Result.map ((+) 1) r) + "," + string (Result.bind (fun _ -> Error "e") r : Result<int, string>)Microsoft.FSharp.Core.FSharpResult`2[System.Int32,System.String],Microsoft.FSharp.Core.FSharpResult`2[System.Int32,System.String][object Object],[object Object]datetime.tostringDates, math and conversionsDateTime.ToString() uses the browser's locale (toLocaleString), as .NET uses the current culture, so the text depends on where it runs (the check runs .NET with the invariant culture).
Instead:Pass a format, such as ToString("yyyy-MM-dd HH:mm:ss"), for a fixed text.
The case
string (d ())02/29/2024 13:45:302/29/2024, 1:45:30 PMNot matching .NET yet
These cases are not accepted differences: 19 give a different result in JavaScript and 8 are rejected by the compiler. They are gaps to fix in WebSharper, and the check turns them green as they are fixed.
19 different results8 rejected at compile time
- Different result:Numbers
float.tostring.largestring 1e21 + "," + string 123456789012.0.NET1E+21,123456789012JS1e+21,123456789012 - Different result:Numbers
float.tostring.smallstring 1e-7.NET1E-07JS1e-7 - Not supported:Strings and printf
interp.typedlet x = n 3 in $"%d{x}|%5d{x}|%-3d{x}|".NET3| 3|3 |JScompile error: not supported - Not supported:Strings and printf
interp.formatlet x = 3.14159 in $"{x:F2}".NET3.14JScompile error: not supported - Different result:Strings and printf
sprintf.f.roundingsprintf "%.0f|%.0f|%.1f" 0.5 1.5 0.25.NET0|2|0.2JS1|2|0.3 - Different result:Strings and printf
sprintf.esprintf "%e|%.2e" 12345.678 12345.678.NET1.234568e+004|1.23e+004JS1.2345678e+4|1.2345678e+4 - Not supported:Strings and printf
sprintf.gsprintf "%g|%g|%g" 0.0001 123456789.0 1.5.NET0.0001|1.23457e+08|1.5JScompile error: not supported - Different result:Strings and printf
sprintf.starsprintf "%*d|%.*f" 5 (n 42) 2 3.14159.NET42|3.14JS42|2.000 - Different result:Strings and printf
sprintf.A.floatsprintf "%A|%A|%A" 1.0 1.5 nan.NET1.0|1.5|nanJS1|1.5|NaN - Different result:Strings and printf
sprintf.A.optionsprintf "%A|%A" (Some 1) (None: int option).NETSome 1|NoneJSSome 1|null - Different result:Strings and printf
sprintf.A.recordsprintf "%A" { Name = "Ann"; Age = 30 }.NET{ Name = "Ann"\n Age = 30 }JS{Name = "Ann"; Age = 30} - Different result:Strings and printf
sprintf.A.charsprintf "%A" 'c'.NET'c'JS"c" - Different result:Strings and printf
sprintf.A.unitsprintf "%A" ().NET()JSnull - Different result:Strings and printf
sprintf.A.mapsprintf "%A" (Map.ofList [ 1, "a" ]).NETmap [(1, "a")]JS{tree = {Node = {Key = 1; Value = "a"}; Left = null; Right = null; Height = 1; Count = 1}} - Different result:Strings and printf
record.tostringstring { Name = "Ann"; Age = 30 }.NET{ Name = "Ann"\n Age = 30 }JS[object Object] - Different result:Strings and printf
union.tostringstring (UB 1) + "|" + string UA.NETUB 1|UAJS[object Object]|[object Object] - Different result:Maps, sets and dictionaries
dictionary.readonly.dictlet d = dict [ 1, "a" ] in try d.[2] <- "b"; "set" with e -> "EXN".NETEXNJSset - Not supported:Language
inline.srtpstring (twice 3) + "," + twice "ab" + "," + string (twice 1.5).NET6,abab,3JScompile error: not supported - Different result:Language
class.static.letlet before = Counter.Created in Counter() |> ignore; string (Counter.Created - before).NET1JS0 - Not supported:Language
object.expression.overridelet o = { new Object() with override _.ToString() = "custom" } in string o.NETcustomJScompile error: not supported - Different result:Language
interface.cast.faillet o = box (Counter()) in try (o :?> IShape).Name with :? InvalidCastException -> "cast".NETcastJS<null> - Different result:Language
downcast.faillet o = box "s" in try string (unbox<int> o) with :? InvalidCastException -> "cast".NETcastJSs - Not supported:Dates, math and conversions
datetimeoffsetlet x = DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero) in string (x.ToUnixTimeSeconds()).NET1704067200JScompile error: not supported - Different result:Dates, math and conversions
timespan.tostringstring (TimeSpan(1, 2, 3, 4)) + "|" + string (TimeSpan.FromMinutes 90.5).NET1.02:03:04|01:30:30JS93784000|5430000 - Different result:Dates, math and conversions
timespan.negativestring (TimeSpan.FromSeconds -61.0).NET-00:01:01JS-61000 - Not supported:Dates, math and conversions
bitconverterstring (BitConverter.GetBytes(1).Length).NET4JScompile error: not supported - Not supported:Dates, math and conversions
urilet u = Uri "https://example.com:8080/a/b?q=1" in u.Host + "," + string u.Port + "," + u.AbsolutePath.NETexample.com,8080,/a/bJScompile error: not supported
Every case
Each row is the F# that runs and the output .NET prints; a passing case prints exactly the same in JavaScript.
Numbers74 / 79 same as .NET
- Same result as .NET:
int.overflow.wrapsstring (big () + 1)-2147483648 - Same result as .NET:
int.multiply.wrapsstring (big () * 2)-2 - Same result as .NET:
int.negate.minstring (-(Int32.MinValue + n 0))-2147483648 - Same result as .NET:
int.division.truncatesstring (-7 / n 2) + "," + string (7 / n -2)-3,-3 - Same result as .NET:
int.remainder.signstring (-7 % n 3) + "," + string (7 % n -3)-1,1 - Same result as .NET:
int.divide.zerostring (1 / zero ())EXN DivideByZero - Same result as .NET:
int.modulo.zerostring (1 % zero ())EXN DivideByZero - Same result as .NET:
int64.overflow.wrapsstring (bigL () + 1L)-9223372036854775808 - Same result as .NET:
int64.largestring (9007199254740993L + int64 (n 0))9007199254740993 - Same result as .NET:
int64.multiplystring (123456789L * int64 (n 1000000))123456789000000 - Same result as .NET:
int64.divisionstring (-9000000000000000007L / int64 (n 2))-4500000000000000003 - Same result as .NET:
uint32.wrapsstring (0u - uint32 (n 1))4294967295 - Same result as .NET:
byte.wrapsstring (255uy + byte (n 1))0 - Same result as .NET:
sbyte.wrapsstring (127y + sbyte (n 1))-128 - Same result as .NET:
int16.wrapsstring (32767s + int16 (n 1))-32768 - Same result as .NET:
int.multiply.largelet x = (1 <<< 28) + n 1 in string (x * x) + "," + string (uint32 (n -1) * uint32 (n -1))536870913,1 - Same result as .NET:
int.wrap.chainstring (big () + big () + big ()) + "," + string (big () * 3 + n 7) + "," + B (big () + 1 > 0)2147483645,-2147483644,false - Same result as .NET:
uint32.dividestring (uint32 (n -6) / 1u) + "," + string (int16 (n -32768) / -1s) + "," + string (sbyte (n -128) / -1y)4294967290,-32768,-128 - Same result as .NET:
narrow.bitwisestring (~~~ (byte (n 250))) + "," + string (byte (n 250) <<< 1) + "," + string (1uy <<< n 9) + "," + string (120y <<< n 1) + "," + string (~~~ (uint16 (n 0)))5,244,2,-16,65535 - Same result as .NET:
shift.count.maskstring (1L <<< n 65) + "," + string (-8L >>> n -1) + "," + string (n 1 <<< n 33) + "," + string (~~~ (uint64 (n 0)))2,-1,2,18446744073709551615 - Same result as .NET:
checked.okstring (Checked.(+) 1 (n 2)) + "," + string (Checked.int64 (n 5)) + "," + string (Checked.byte 2.7) + "," + string (Checked.(~-) (n 4))3,5,2,-4 - Same result as .NET:
checked.overflow.morelet t f = (try string (f ()) with :? OverflowException -> "overflow") in t (fun () -> Checked.(*) (big ()) 2) + "," + t (fun () -> Checked.byte (n 300)) + "," + t (fun () -> Checked.(-) Int32.MinValue (n 1)) + "," + t (fun () -> Checked.int nan)overflow,overflow,overflow,overflow - Same result as .NET:
uint64.maxstring (UInt64.MaxValue - uint64 (n 0))18446744073709551615 - Same result as .NET:
checked.overflowstring (Checked.(+) (big ()) 1)EXN Overflow - Same result as .NET:
checked.int.conversionstring (Checked.int 3000000000.0)EXN Overflow - Same result as .NET:
conversion.int.of.floatstring (int 3.99) + "," + string (int -3.99)3,-3 - Same result as .NET:
conversion.byte.of.intstring (byte (n 300))44 - Same result as .NET:
conversion.int.of.stringstring (int "42")42 - Same result as .NET:
conversion.int.of.bad.stringstring (int "4x2")EXN Format - Same result as .NET:
conversion.float.of.stringstring (float "2.5")2.5 - Same result as .NET:
conversion.int.of.charstring (int 'A')65 - Same result as .NET:
conversion.char.of.intstring (char (n 66))B - Same result as .NET:
conversion.int64.of.intstring (int64 (n -5))-5 - Same result as .NET:
conversion.uint32.of.negativestring (uint32 (n -1))4294967295 - Same result as .NET:
int.parsestring (Int32.Parse "-17")-17 - Same result as .NET:
int.parse.badstring (Int32.Parse "abc")EXN Format - Same result as .NET:
int.parse.overflowstring (Int32.Parse "3000000000")EXN Overflow - Same result as .NET:
int.tryparsematch Int32.TryParse "12" with | true, v -> string v | _ -> "no"12 - Same result as .NET:
int.tryparse.badmatch Int32.TryParse "1.5" with | true, v -> string v | _ -> "no"no - Same result as .NET:
float.tostringstring 1.5 + "," + string 2.0 + "," + string 0.11.5,2,0.1 - Different result:
float.tostring.largestring 1e21 + "," + string 123456789012.0.NET1E+21,123456789012JS1e+21,123456789012 - Different result:
float.tostring.smallstring 1e-7.NET1E-07JS1e-7 - Same result as .NET:
float.nanstring nan + "," + string infinity + "," + string -infinityNaN,Infinity,-Infinity - Same result as .NET:
float.divide.zerostring (1.0 / zeroF ())Infinity - Same result as .NET:
float.nan.equalityB (nan = nan) + "," + B (nan <> nan)false,true - Same result as .NET:
float.compare.nanstring (compare nan 1.0)-1 - Same result as .NET:
float.round.bankerstring (round 2.5) + "," + string (round 3.5) + "," + string (round -2.5)2,4,-2 - Same result as .NET:
float.math.roundstring (Math.Round 0.5) + "," + string (Math.Round 1.5)0,2 - Same result as .NET:
float.math.round.digitsstring (Math.Round(2.345, 2))2.35 - Same result as .NET:
float.truncatestring (truncate -2.7) + "," + string (floor -2.7) + "," + string (ceil -2.2)-2,-3,-2 - Same result as .NET:
float32.precisionstring (float32 0.1)0.1 - Known difference:
float32.arithstring (0.1f + 0.2f).NET0.3JS0.30000000000000004 - Same result as .NET:
float.sumstring (0.1 + 0.2)0.30000000000000004 - Same result as .NET:
float.parsestring (Double.Parse "1e3")1000 - Same result as .NET:
float.tostring.format(3.14159).ToString("F2")3.14 - Same result as .NET:
float.tostring.n(1234567.891).ToString("N2")1,234,567.89 - Same result as .NET:
int.tostring.d(42).ToString("D5")00042 - Same result as .NET:
int.tostring.x(255).ToString("X") + "," + (255).ToString("x4")FF,00ff - Known difference:
decimal.addstring (0.1M + 0.2M).NET0.3JScompile error: not supported - Known difference:
decimal.dividestring (1M / 3M).NET0.3333333333333333333333333333JScompile error: not supported - Same result as .NET:
bigint.powstring (bigint 2 ** 100)1267650600228229401496703205376 - Same result as .NET:
bigint.dividestring (bigint.Parse "1000000000000000000000" / bigint 7)142857142857142857142 - Same result as .NET:
pownstring (pown 2 10) + "," + string (pown 2.0 -2)1024,0.25 - Same result as .NET:
abs.signstring (abs (n -5)) + "," + string (sign (n -5)) + "," + string (sign -0.0)5,-1,0 - Same result as .NET:
abs.min.intstring (abs Int32.MinValue)EXN Overflow - Same result as .NET:
min.maxstring (min 3 (n 5)) + "," + string (max 3.0 nan)3,NaN - Same result as .NET:
sqrt.negativestring (sqrt -1.0)NaN - Same result as .NET:
math.powstring (2.0 ** 0.5)1.4142135623730951 - Same result as .NET:
bitwise.opsstring (n 12 &&& 10) + "," + string (n 12 ||| 3) + "," + string (n 12 ^^^ 5) + "," + string (~~~ (n 0))8,15,9,-1 - Same result as .NET:
bitwise.shiftstring (n 1 <<< 31) + "," + string (n -16 >>> 2) + "," + string (n 1 <<< 33)-2147483648,-4,2 - Same result as .NET:
bitwise.shift.uintstring (0x80000000u >>> 31)1 - Same result as .NET:
bitwise.int64string (1L <<< 40)1099511627776 - Same result as .NET:
hex.literalstring 0xFF + "," + string 0b1010 + "," + string 0o17255,10,15 - Same result as .NET:
int.comparestring (compare 1 (n 2)) + "," + string (compare "b" "a")-1,1 - Same result as .NET:
int.max.valuestring Int32.MaxValue + "," + string Int64.MinValue2147483647,-9223372036854775808 - Same result as .NET:
char.arithstring (char (int 'a' + n 1))b - Same result as .NET:
range.stepJi [ 10 .. -3 .. 0 ][10,7,4,1] - Same result as .NET:
range.floatJ (List.map string [ 0.0 .. 0.5 .. 1.5 ])[0,0.5,1,1.5] - Same result as .NET:
incr.decrlet r = ref 0 in incr r; incr r; decr r; string r.Value1
Strings and printf87 / 106 same as .NET
- Same result as .NET:
string.lengthstring (s "héllo").Length5 - Same result as .NET:
string.indexstring (s "abc").[1]b - Known difference:
string.index.out.of.rangestring (s "abc").[5].NETEXN IndexOutOfRangeJS<null> - Same result as .NET:
string.slice(s "abcdef").[1..3] + "," + (s "abcdef").[..1] + "," + (s "abcdef").[4..]bcd,ab,ef - Same result as .NET:
string.slice.out.of.range(s "abc").[1..10]bc - Same result as .NET:
string.substring(s "abcdef").Substring(2, 3)cde - Same result as .NET:
string.substring.bad(s "abc").Substring(2, 5)EXN ArgumentOutOfRange - Known difference:
string.concat.nulls "a" + (null: string) + "b".NETabJSanullb - Same result as .NET:
string.of.null"[" + string (null: string) + "]"[] - Same result as .NET:
string.of.optionstring (Some 1) + "|" + string (None: int option)Some(1)| - Same result as .NET:
string.of.unit"[" + string () + "]"[] - Same result as .NET:
string.of.boolstring true + "," + string falseTrue,False - Same result as .NET:
string.of.charstring 'x'x - Same result as .NET:
string.of.liststring [1; 2; 3][1; 2; 3] - Same result as .NET:
string.of.tuplestring (1, "a")(1, a) - Same result as .NET:
string.of.list.longstring [ 1 .. 10 ] + "|" + string ([]: int list)[1; 2; 3; ... ]|[] - Same result as .NET:
string.of.list.nestedstring [ "a"; "b" ] + "|" + string [ true ] + "|" + string [ Some 1 ] + "|" + string [ [ 1 ]; [ 2 ] ] + "|" + string [ (null: string); "a" ] + "|" + string [ (None: int option) ][a; b]|[True]|[Some(1)]|[[1]; [2]]|[null; a]|[null] - Same result as .NET:
string.of.option.nestedstring (Some (Some 1)) + "|" + string (Some true) + "|" + string (Some [ 1; 2 ]) + "|" + string (Some (1, 2)) + "|" + string (Some (null: string)) + "|" + string (Some (None: int option))Some(Some(1))|Some(True)|Some([1; 2])|Some((1, 2))|Some(null)|Some(null) - Same result as .NET:
string.of.tuple.nestedstring (1, true, 2.5) + "|" + string (1, (2, 3)) + "|" + string (Some 1, (None: int option)) + "|" + string ((null: string), 1)(1, True, 2.5)|(1, (2, 3))|(Some(1), )|(, 1) - Same result as .NET:
string.of.objstring (box true) + "|" + string (null: obj) + "|" + string (box 3)True||3 - Same result as .NET:
string.splitJ ((s "a,b,,c").Split(','))[a,b,,c] - Same result as .NET:
string.split.optionsJ ((s "a,b,,c").Split([| ',' |], StringSplitOptions.RemoveEmptyEntries))[a,b,c] - Same result as .NET:
string.split.stringJ ((s "a--b--c").Split([| "--" |], StringSplitOptions.None))[a,b,c] - Same result as .NET:
string.trim"[" + (s " x ").Trim() + "][" + (s "xxaxx").Trim('x') + "][" + (s " x").TrimStart() + "]"[x][a][x] - Same result as .NET:
string.pad(s "7").PadLeft(3, '0') + "," + (s "ab").PadRight(4, '.')007,ab.. - Same result as .NET:
string.replace(s "a.b.c").Replace(".", "--") + "," + (s "aaa").Replace('a', 'b')a--b--c,bbb - Same result as .NET:
string.indexofstring ((s "hello").IndexOf "l") + "," + string ((s "hello").LastIndexOf 'l') + "," + string ((s "hello").IndexOf "z")2,3,-1 - Same result as .NET:
string.indexof.startstring ((s "hello").IndexOf("l", 3))3 - Same result as .NET:
string.containsB ((s "hello").Contains "ell") + "," + B ((s "hello").StartsWith "he") + "," + B ((s "hello").EndsWith "lo")true,true,true - Same result as .NET:
string.case(s "Hello").ToUpper() + "," + (s "Hello").ToLower()HELLO,hello - Same result as .NET:
string.case.invariant(s "Hello").ToUpperInvariant() + "," + (s "Hello").ToLowerInvariant()HELLO,hello - Same result as .NET:
string.compare.ordinalstring (sign (String.CompareOrdinal(s "a", s "B")))1 - Same result as .NET:
string.compare.fsharpstring (sign (compare (s "a") (s "B"))) + "," + string (sign (compare (s "apple") (s "Apple")))1,1 - Same result as .NET:
string.sort.fsharpJ (List.sort [ s "b"; "B"; "a"; "A" ])[A,B,a,b] - Same result as .NET:
string.equals.ignorecaseB (String.Equals(s "abc", s "ABC", StringComparison.OrdinalIgnoreCase))true - Same result as .NET:
string.isnulloremptyB (String.IsNullOrEmpty null) + "," + B (String.IsNullOrWhiteSpace " ")true,true - Same result as .NET:
string.joinString.Join("-", [| "a"; "b"; "c" |]) + "," + String.Join(",", [ 1; 2 ])a-b-c,1,2 - Same result as .NET:
string.concat.arrayString.Concat([| "a"; "b" |])ab - Same result as .NET:
string.reverseString(Array.rev ((s "abc").ToCharArray()))cba - Same result as .NET:
string.ctor.repeatString('x', n 3)xxx - Same result as .NET:
string.insert.remove(s "abc").Insert(1, "XY") + "," + (s "abcdef").Remove(1, 2)aXYbc,adef - Known difference:
string.equalityB (s "abc" = "a" + "bc") + "," + B (obj.ReferenceEquals(s "abc", "a" + s "bc")).NETtrue,falseJStrue,true - Same result as .NET:
string.module.concatString.concat ", " [ "a"; "b" ]a, b - Same result as .NET:
string.module.mapString.map Char.ToUpper (s "abc")ABC - Same result as .NET:
string.module.collectString.collect (fun c -> string c + string c) (s "ab")aabb - Same result as .NET:
string.module.initString.init 3 (fun i -> string i)012 - Same result as .NET:
string.module.replicateString.replicate 3 (s "ab")ababab - Same result as .NET:
string.module.forallB (String.forall Char.IsDigit (s "123")) + "," + B (String.exists Char.IsUpper (s "abC"))true,true - Same result as .NET:
string.module.filterString.filter Char.IsLetter (s "a1b2")ab - Same result as .NET:
string.module.length.nullstring (String.length null)0 - Same result as .NET:
string.seqJ (s "abc" |> Seq.map string |> Seq.rev)[c,b,a] - Same result as .NET:
string.toCharArraystring ((s "abc").ToCharArray().Length)3 - Same result as .NET:
char.testsB (Char.IsDigit '5') + "," + B (Char.IsLetter 'é') + "," + B (Char.IsWhiteSpace '\t') + "," + B (Char.IsUpper 'A')true,true,true,true - Same result as .NET:
char.casestring (Char.ToUpper 'a') + string (Char.ToLower 'Q') + string (Char.ToUpperInvariant 'é') + "," + B (Char.IsLower 'é') + B (Char.IsDigit '٣')AqÉ,truetrue - Known difference:
char.unicode.upperstring (Char.ToUpper 'ß') + "," + (s "straße").ToUpper().NETß,STRAßEJSß,STRASSE - Same result as .NET:
char.surrogate.lengthstring (s "😀").Length2 - Same result as .NET:
stringbuilderlet sb = StringBuilder() in sb.Append("a").Append(1).Append('c') |> ignore; sb.ToString()a1c - Same result as .NET:
stringbuilder.appendlinelet sb = StringBuilder() in sb.AppendLine("a") |> ignore; string sb.Length2 - Same result as .NET:
interp.basiclet x = n 3 in $"x={x}"x=3 - Same result as .NET:
interp.adjacentlet a, b = n 1, n 2 in $"{a}{b}"12 - Not supported:
interp.typedlet x = n 3 in $"%d{x}|%5d{x}|%-3d{x}|".NET3| 3|3 |JScompile error: not supported - Not supported:
interp.formatlet x = 3.14159 in $"{x:F2}".NET3.14JScompile error: not supported - Same result as .NET:
interp.floatlet x = 2.0 in $"{x}"2 - Same result as .NET:
interp.stringlet x = s "q" in $"[%s{x}]"[q] - Same result as .NET:
interp.verbatimlet x = n 1 in $"""{x} "quoted" """1 "quoted" - Same result as .NET:
escape.sequencesstring (s "a\tb\n").Length4 - Same result as .NET:
triple.quoted"""a"b"""a"b - Same result as .NET:
sprintf.dsprintf "%d|%i|%5d|%-5d|%05d" (n 42) (n 42) (n 42) (n 42) (n 42)42|42| 42|42 |00042 - Same result as .NET:
sprintf.d.negativesprintf "%05d|%+d" (n -42) (n 42)-0042|+42 - Same result as .NET:
sprintf.ssprintf "[%s][%5s][%-5s]" "ab" "ab" "ab"[ab][ ab][ab ] - Same result as .NET:
sprintf.s.nullsprintf "[%s]" (null: string)[] - Same result as .NET:
sprintf.fsprintf "%f|%.2f|%8.3f|%-8.1f|" 3.14159 3.14159 3.14159 3.141593.141590|3.14| 3.142|3.1 | - Different result:
sprintf.f.roundingsprintf "%.0f|%.0f|%.1f" 0.5 1.5 0.25.NET0|2|0.2JS1|2|0.3 - Different result:
sprintf.esprintf "%e|%.2e" 12345.678 12345.678.NET1.234568e+004|1.23e+004JS1.2345678e+4|1.2345678e+4 - Not supported:
sprintf.gsprintf "%g|%g|%g" 0.0001 123456789.0 1.5.NET0.0001|1.23457e+08|1.5JScompile error: not supported - Same result as .NET:
sprintf.xsprintf "%x|%X|%04x|%o" (n 255) (n 255) (n 255) (n 8)ff|FF|00ff|10 - Same result as .NET:
sprintf.x.negativesprintf "%x" (n -1)ffffffff - Same result as .NET:
sprintf.csprintf "%c%c" 'o' 'k'ok - Same result as .NET:
sprintf.bsprintf "%b|%b" true falsetrue|false - Same result as .NET:
sprintf.percentsprintf "100%%"100% - Different result:
sprintf.starsprintf "%*d|%.*f" 5 (n 42) 2 3.14159.NET42|3.14JS42|2.000 - Same result as .NET:
sprintf.Osprintf "%O|%O" (n 1) "s"1|s - Same result as .NET:
sprintf.A.intsprintf "%A" (n 42)42 - Same result as .NET:
sprintf.A.stringsprintf "%A" "hi""hi" - Different result:
sprintf.A.floatsprintf "%A|%A|%A" 1.0 1.5 nan.NET1.0|1.5|nanJS1|1.5|NaN - Same result as .NET:
sprintf.A.listsprintf "%A" [ 1; 2; 3 ][1; 2; 3] - Same result as .NET:
sprintf.A.arraysprintf "%A" [| 1; 2 |][|1; 2|] - Same result as .NET:
sprintf.A.tuplesprintf "%A" (1, "a", true)(1, "a", true) - Different result:
sprintf.A.optionsprintf "%A|%A" (Some 1) (None: int option).NETSome 1|NoneJSSome 1|null - Different result:
sprintf.A.recordsprintf "%A" { Name = "Ann"; Age = 30 }.NET{ Name = "Ann"\n Age = 30 }JS{Name = "Ann"; Age = 30} - Same result as .NET:
sprintf.A.unionsprintf "%A|%A|%A" UA (UB 1) (UC ("x", 2.5))UA|UB 1|UC ("x", 2.5) - Same result as .NET:
sprintf.A.nestedsprintf "%A" [ Some (1, "a") ][Some (1, "a")] - Different result:
sprintf.A.charsprintf "%A" 'c'.NET'c'JS"c" - Different result:
sprintf.A.unitsprintf "%A" ().NET()JSnull - Different result:
sprintf.A.mapsprintf "%A" (Map.ofList [ 1, "a" ]).NETmap [(1, "a")]JS{tree = {Node = {Key = 1; Value = "a"}; Left = null; Right = null; Height = 1; Count = 1}} - Same result as .NET:
sprintf.partiallet f = sprintf "%d-%s" in f 1 "a" + "," + f 2 "b"1-a,2-b - Same result as .NET:
sprintf.int64sprintf "%d" 9007199254740993L9007199254740993 - Same result as .NET:
sprintf.usprintf "%u" 4294967295u4294967295 - Known difference:
sprintf.Msprintf "%M" 1.50M.NET1.50JScompile error: not supported - Same result as .NET:
failwithftry failwithf "bad %d" (n 7) with e -> e.Messagebad 7 - Same result as .NET:
string.formatString.Format("{0}-{1}", n 1, "a")1-a - Same result as .NET:
string.format.alignString.Format("[{0,5}][{0,-5}]", n 42)[ 42][42 ] - Same result as .NET:
string.format.specString.Format("{0:F1}|{0:N0}|{1:X2}", 1234.56, n 10)1234.6|1,235|0A - Same result as .NET:
string.format.escapeString.Format("{{{0}}}", n 1){1} - Different result:
record.tostringstring { Name = "Ann"; Age = 30 }.NET{ Name = "Ann"\n Age = 30 }JS[object Object] - Different result:
union.tostringstring (UB 1) + "|" + string UA.NETUB 1|UAJS[object Object]|[object Object]
Lists, arrays and sequences126 / 126 same as .NET
- Same result as .NET:
list.basicsstring (List.length (l ())) + "," + string (List.head (l ())) + "," + Ji (List.tail (l ()))8,3,[1,4,1,5,9,2,6] - Same result as .NET:
list.head.emptystring (List.head (e ()))EXN Argument - Same result as .NET:
list.cons.appendJi (0 :: [ 1 ] @ [ 2; 3 ])[0,1,2,3] - Same result as .NET:
list.map.filterJi (l () |> List.filter (fun x -> x % 2 = 1) |> List.map (fun x -> x * 10))[30,10,10,50,90] - Same result as .NET:
list.sortJi (List.sort (l ())) + Ji (List.sortDescending (l ()))[1,1,2,3,4,5,6,9][9,6,5,4,3,2,1,1] - Same result as .NET:
list.sort.stableJ ([ "bb"; "a"; "cc"; "d" ] |> List.sortBy String.length)[a,d,bb,cc] - Same result as .NET:
list.sortwithJi (List.sortWith (fun a b -> compare b a) (l ()))[9,6,5,4,3,2,1,1] - Same result as .NET:
list.foldstring (List.fold (fun acc x -> acc * 10 + x) 0 [ 1; 2; 3 ]) + "," + string (List.foldBack (fun x acc -> acc * 10 + x) [ 1; 2; 3 ] 0)123,321 - Same result as .NET:
list.reducestring (List.reduce (-) [ 10; 2; 3 ]) + "," + string (List.reduceBack (-) [ 10; 2; 3 ])5,11 - Same result as .NET:
list.reduce.emptystring (List.reduce (+) (e ()))EXN Argument - Same result as .NET:
list.scanJi (List.scan (+) 0 [ 1; 2; 3 ])[0,1,3,6] - Same result as .NET:
list.sum.averagestring (List.sum (l ())) + "," + string (List.average [ 1.0; 2.0 ]) + "," + string (List.sumBy float [ 1; 2 ])31,1.5,3 - Same result as .NET:
list.average.emptystring (List.average ([]: float list))EXN Argument - Same result as .NET:
list.minmaxstring (List.max (l ())) + "," + string (List.min (l ())) + "," + string (List.maxBy (fun x -> -x) (l ()))9,1,1 - Same result as .NET:
list.distinctJi (List.distinct (l ())) + Ji (List.distinctBy (fun x -> x % 3) (l ()))[3,1,4,5,9,2,6][3,1,5] - Same result as .NET:
list.groupbyJ (l () |> List.groupBy (fun x -> x % 3) |> List.map (fun (k, xs) -> string k + ":" + Ji xs))[0:[3,9,6],1:[1,4,1],2:[5,2]] - Same result as .NET:
list.countbyJ (l () |> List.countBy (fun x -> x > 3) |> List.map (fun (k, c) -> string k + ":" + string c))[False:4,True:4] - Same result as .NET:
list.partitionlet a, b = List.partition (fun x -> x > 3) (l ()) in Ji a + Ji b[4,5,9,6][3,1,1,2] - Same result as .NET:
list.chunkJ (List.chunkBySize 3 (l ()) |> List.map Ji)[[3,1,4],[1,5,9],[2,6]] - Same result as .NET:
list.windowedJ (List.windowed 3 [ 1; 2; 3; 4 ] |> List.map Ji)[[1,2,3],[2,3,4]] - Same result as .NET:
list.pairwiseJ (List.pairwise [ 1; 2; 3 ] |> List.map (fun (a, b) -> string a + string b))[12,23] - Same result as .NET:
list.zipJ (List.zip [ 1; 2 ] [ "a"; "b" ] |> List.map (fun (a, b) -> string a + b))[1a,2b] - Same result as .NET:
list.zip.mismatchstring (List.length (List.zip [ 1; 2 ] [ "a" ]))EXN Argument - Same result as .NET:
list.unziplet a, b = List.unzip [ 1, "a"; 2, "b" ] in Ji a + J b[1,2][a,b] - Same result as .NET:
list.collectJi (List.collect (fun x -> [ x; x ]) [ 1; 2 ])[1,1,2,2] - Same result as .NET:
list.chooseJi (List.choose (fun x -> if x > 3 then Some (x * 2) else None) (l ()))[8,10,18,12] - Same result as .NET:
list.findstring (List.find (fun x -> x > 4) (l ())) + "," + string (List.findIndex (fun x -> x > 4) (l ())) + "," + string (List.findBack (fun x -> x < 3) (l ()))5,4,2 - Same result as .NET:
list.find.missingstring (List.find (fun x -> x > 100) (l ()))EXN KeyNotFound - Same result as .NET:
list.tryfindstring (List.tryFind (fun x -> x > 100) (l ())) + "," + string (List.tryFindIndex (fun x -> x = 5) (l ())),Some(4) - Same result as .NET:
list.pickstring (List.pick (fun x -> if x > 4 then Some (x * 100) else None) (l ()))500 - Same result as .NET:
list.existsB (List.exists ((=) 9) (l ())) + "," + B (List.forall (fun x -> x > 0) (l ())) + "," + B (List.contains 7 (l ()))true,true,false - Same result as .NET:
list.take.skipJi (List.take 2 (l ())) + Ji (List.skip 6 (l ())) + Ji (List.truncate 20 [ 1 ])[3,1][2,6][1] - Same result as .NET:
list.take.too.manyJi (List.take 20 (l ()))EXN InvalidOperation - Same result as .NET:
list.takewhileJi (List.takeWhile (fun x -> x > 2) (l ())) + Ji (List.skipWhile (fun x -> x > 2) (l ()))[3][1,4,1,5,9,2,6] - Same result as .NET:
list.itemstring (List.item 2 (l ())) + "," + string (l ()).[3]4,1 - Same result as .NET:
list.item.out.of.rangestring (List.item 20 (l ()))EXN Argument - Same result as .NET:
list.laststring (List.last (l ())) + "," + string (List.tryLast (e ()))6, - Same result as .NET:
list.revJi (List.rev [ 1; 2; 3 ])[3,2,1] - Same result as .NET:
list.init.replicateJi (List.init 3 (fun i -> i * i)) + Ji (List.replicate 2 7)[0,1,4][7,7] - Same result as .NET:
list.mapi.indexedJ (List.mapi (fun i x -> string i + "=" + string x) [ 5; 6 ]) + J (List.indexed [ 'a' ] |> List.map string)[0=5,1=6][(0, a)] - Same result as .NET:
list.map2.map3Ji (List.map2 (+) [ 1; 2 ] [ 10; 20 ]) + Ji (List.map3 (fun a b c -> a + b + c) [ 1 ] [ 2 ] [ 3 ])[11,22][6] - Same result as .NET:
list.iterlet mutable s = "" in List.iteri (fun i x -> s <- s + string i + string x) [ 7; 8 ]; s0718 - Same result as .NET:
list.exceptJi (List.except [ 1; 5 ] (l ()))[3,4,9,2,6] - Same result as .NET:
list.splitatlet a, b = List.splitAt 3 (l ()) in Ji a + Ji b[3,1,4][1,5,9,2,6] - Same result as .NET:
list.allpairsJ (List.allPairs [ 1; 2 ] [ 'a'; 'b' ] |> List.map (fun (a, b) -> string a + string b))[1a,1b,2a,2b] - Same result as .NET:
list.transposeJ (List.transpose [ [ 1; 2 ]; [ 3; 4 ] ] |> List.map Ji)[[1,3],[2,4]] - Same result as .NET:
list.unfoldJi (List.unfold (fun x -> if x > 20 then None else Some (x, x * 2)) 1)[1,2,4,8,16] - Same result as .NET:
list.mapfoldlet r, s = List.mapFold (fun acc x -> x * 2, acc + x) 0 [ 1; 2; 3 ] in Ji r + string s[2,4,6]6 - Same result as .NET:
list.equalityB ([ 1; 2 ] = [ 1; 2 ]) + "," + B ([ 1; 2 ] < [ 1; 3 ]) + "," + string (compare [ 1; 2 ] [ 1 ])true,true,1 - Same result as .NET:
list.comprehensionJi [ for x in 1 .. 4 do if x % 2 = 0 then yield x * x ][4,16] - Same result as .NET:
list.comprehension.nestedJ [ for a in 1 .. 2 do for b in [ "x"; "y" ] -> string a + b ][1x,1y,2x,2y] - Same result as .NET:
list.updateatJi (List.updateAt 1 9 [ 1; 2; 3 ]) + Ji (List.insertAt 0 0 [ 1 ]) + Ji (List.removeAt 0 [ 1; 2 ])[1,9,3][0,1][2] - Same result as .NET:
list.exactlyonestring (List.exactlyOne [ 4 ]) + "," + string (List.tryExactlyOne [ 1; 2 ])4, - Same result as .NET:
list.randomless.permuteJi (List.permute (fun i -> (i + 1) % 3) [ 1; 2; 3 ])[3,1,2] - Same result as .NET:
array.basicslet x = a () in x.[0] <- 9; Ji x + string x.Length[9,1,4,1,5]5 - Same result as .NET:
array.index.out.of.rangestring (a ()).[10]EXN IndexOutOfRange - Same result as .NET:
array.set.out.of.rangelet x = a () in x.[10] <- 1; "set"EXN IndexOutOfRange - Same result as .NET:
array.sliceJi (a ()).[1..2] + Ji (a ()).[3..] + Ji (a ()).[..0][1,4][1,5][3] - Same result as .NET:
array.slice.emptyJi (a ()).[3..1][] - Same result as .NET:
array.create.zeroJi (Array.zeroCreate 3) + J (Array.create 2 "x")[0,0,0][x,x] - Same result as .NET:
array.zerocreate.stringlet x : string[] = Array.zeroCreate 1 in B (isNull x.[0])true - Same result as .NET:
array.sort.inplacelet x = a () in Array.sortInPlace x; Ji x[1,1,3,4,5] - Same result as .NET:
array.sort.copylet x = a () in let y = Array.sort x in Ji x + Ji y[3,1,4,1,5][1,1,3,4,5] - Same result as .NET:
array.map.filterJi (a () |> Array.filter (fun x -> x > 1) |> Array.map (fun x -> x + 1))[4,5,6] - Same result as .NET:
array.foldstring (Array.fold (+) 0 (a ())) + "," + string (Array.sum (a ()))14,14 - Same result as .NET:
array.blitlet x = a () in Array.blit [| 7; 8 |] 0 x 1 2; Ji x[3,7,8,1,5] - Same result as .NET:
array.blit.badlet x = a () in Array.blit [| 7; 8 |] 0 x 4 2; Ji xEXN Argument - Same result as .NET:
array.filllet x = a () in Array.fill x 1 2 0; Ji x[3,0,0,1,5] - Same result as .NET:
array.append.concatJi (Array.append [| 1 |] [| 2 |]) + Ji (Array.concat [ [| 1 |]; [| 2; 3 |] ])[1,2][1,2,3] - Same result as .NET:
array.copy.independentlet x = a () in let y = Array.copy x in y.[0] <- 0; string x.[0]3 - Same result as .NET:
array.revJi (Array.rev (a ()))[5,1,4,1,3] - Same result as .NET:
array.equalityB ([| 1; 2 |] = [| 1; 2 |]) + "," + B (obj.ReferenceEquals([| 1 |], [| 1 |]))true,false - Same result as .NET:
array.comparestring (compare [| 1; 2 |] [| 1; 3 |]) + "," + string (compare [| 1; 2; 3 |] [| 2 |])-1,1 - Same result as .NET:
array.hash.equalB (hash [| 1; 2 |] = hash [| 1; 2 |])true - Same result as .NET:
array.containsB (Array.contains 4 (a ())) + "," + string (Array.IndexOf(a (), 1))true,1 - Same result as .NET:
array.initJi (Array.init 4 (fun i -> i * 2))[0,2,4,6] - Same result as .NET:
array.binarysearchstring (Array.BinarySearch([| 1; 3; 5; 7 |], 5))2 - Same result as .NET:
array.resizelet mutable x = [| 1; 2 |] in Array.Resize(&x, 4); Ji x[1,2,0,0] - Same result as .NET:
array.reverse.inplacelet x = a () in Array.Reverse x; Ji x[5,1,4,1,3] - Same result as .NET:
array.sortby.inplacelet x = [| "bb"; "a"; "ccc" |] in Array.sortInPlaceBy String.length x; J x[a,bb,ccc] - Same result as .NET:
array.choose.pickJi (Array.choose (fun x -> if x > 2 then Some x else None) (a ()))[3,4,5] - Same result as .NET:
array.partitionlet p, q = Array.partition (fun x -> x > 2) (a ()) in Ji p + Ji q[3,4,5][1,1] - Same result as .NET:
array.subJi (Array.sub (a ()) 1 3)[1,4,1] - Same result as .NET:
array.sub.badJi (Array.sub (a ()) 3 5)EXN ArgumentOutOfRange - Same result as .NET:
array.max.emptystring (Array.max ([||]: int[]))EXN Argument - Same result as .NET:
array.2dlet m = Array2D.init 2 3 (fun i j -> i * 10 + j) in string m.[1, 2] + "," + string (Array2D.length1 m) + "," + string (Array2D.length2 m)12,2,3 - Same result as .NET:
array.2d.setlet m = Array2D.zeroCreate 2 2 in m.[1, 1] <- 5; string (m.[1, 1] + m.[0, 0])5 - Same result as .NET:
array.jaggedlet m = [| [| 1 |]; [| 2; 3 |] |] in string m.[1].[1]3 - Same result as .NET:
array.comprehensionJi [| for i in 0 .. 3 -> i * i |][0,1,4,9] - Same result as .NET:
array.for.inlet mutable s = 0 in (for x in a () do s <- s + x); string s14 - Same result as .NET:
seq.lazylet mutable n = 0 in let s = Seq.map (fun x -> n <- n + 1; x) [ 1; 2; 3 ] in let _ = Seq.head s in string n1 - Same result as .NET:
seq.reevaluateslet mutable n = 0 in let s = seq { n <- n + 1; yield n } in string (Seq.head s) + string (Seq.head s)12 - Same result as .NET:
seq.cachelet mutable n = 0 in let s = Seq.cache (seq { n <- n + 1; yield n }) in string (Seq.head s) + string (Seq.head s)11 - Same result as .NET:
seq.infiniteJi (Seq.initInfinite (fun i -> i * 3) |> Seq.take 4)[0,3,6,9] - Same result as .NET:
seq.expressionJi (seq { yield 1; yield! [ 2; 3 ]; for i in 4 .. 5 do yield i })[1,2,3,4,5] - Same result as .NET:
seq.whileJi (seq { let mutable i = 0 in while i < 3 do yield i; i <- i + 1 })[0,1,2] - Same result as .NET:
seq.tryfinallylet mutable log = "" in (for x in seq { try yield 1; yield 2 finally log <- log + "F" } do log <- log + string x); log12F - Same result as .NET:
seq.use.disposelet mutable log = "" in let d = { new IDisposable with member _.Dispose() = log <- log + "D" } in (for x in seq { use _ = d in yield 1 } do log <- log + string x); log1D - Same result as .NET:
seq.take.too.manyJi (Seq.take 5 [ 1; 2 ])EXN InvalidOperation - Same result as .NET:
seq.truncateJi (Seq.truncate 5 [ 1; 2 ])[1,2] - Same result as .NET:
seq.skip.too.manyJi (Seq.skip 5 [ 1; 2 ])EXN InvalidOperation - Same result as .NET:
seq.head.emptystring (Seq.head Seq.empty<int>)EXN Argument - Same result as .NET:
seq.zipJ (Seq.zip [ 1; 2; 3 ] [ "a"; "b" ] |> Seq.map (fun (a, b) -> string a + b))[1a,2b] - Same result as .NET:
seq.sortbyJi (Seq.sortBy (fun x -> -x) [ 1; 3; 2 ])[3,2,1] - Same result as .NET:
seq.groupbyJ (Seq.groupBy (fun x -> x % 2) [ 1; 2; 3; 4 ] |> Seq.map (fun (k, xs) -> string k + ":" + Ji xs))[1:[1,3],0:[2,4]] - Same result as .NET:
seq.distinctJi (Seq.distinct [ 3; 1; 3; 2; 1 ])[3,1,2] - Same result as .NET:
seq.comparestring (Seq.compareWith compare [ 1; 2 ] [ 1; 3 ])-1 - Same result as .NET:
seq.lengthstring (Seq.length (seq { 1 .. 10 }))10 - Same result as .NET:
seq.sum.emptystring (Seq.sum Seq.empty<int>)0 - Same result as .NET:
seq.average.emptystring (Seq.average Seq.empty<float>)EXN Argument - Same result as .NET:
seq.itemstring (Seq.item 2 [ 5; 6; 7 ])7 - Same result as .NET:
seq.item.missingstring (Seq.item 5 [ 5; 6; 7 ])EXN Argument - Same result as .NET:
seq.chunkJ (Seq.chunkBySize 2 [ 1; 2; 3 ] |> Seq.map Ji)[[1,2],[3]] - Same result as .NET:
seq.windowedJ (Seq.windowed 2 [ 1; 2; 3 ] |> Seq.map Ji)[[1,2],[2,3]] - Same result as .NET:
seq.pairwiseJ (Seq.pairwise [ 1; 2; 3 ] |> Seq.map (fun (a, b) -> string (a * b)))[2,6] - Same result as .NET:
seq.appendJi (Seq.append [ 1 ] [ 2 ] |> Seq.append [ 0 ])[0,1,2] - Same result as .NET:
seq.concatJi (Seq.concat [ [ 1 ]; []; [ 2; 3 ] ])[1,2,3] - Same result as .NET:
seq.unfoldJi (Seq.unfold (fun (a, b) -> if a > 20 then None else Some (a, (b, a + b))) (0, 1))[0,1,1,2,3,5,8,13] - Same result as .NET:
seq.scanJi (Seq.scan (+) 0 [ 1; 2; 3 ])[0,1,3,6] - Same result as .NET:
seq.existsB (Seq.exists (fun x -> x > 2) [ 1; 3 ]) + "," + B (Seq.forall2 (=) [ 1 ] [ 1 ])true,true - Same result as .NET:
seq.tolist.toarraystring (List.length (Seq.toList (seq { 1 .. 3 }))) + string (Array.length (Seq.toArray [ 1 ]))31 - Same result as .NET:
seq.range.emptyJi (seq { 5 .. 1 })[] - Same result as .NET:
seq.enumeratorlet e = (Seq.ofList [ 1; 2 ]).GetEnumerator() in let a = e.MoveNext() in B a + string e.Currenttrue1 - Same result as .NET:
seq.max.bystring (Seq.maxBy String.length [ "a"; "ccc"; "bb" ])ccc - Same result as .NET:
seq.readonlyJi (Seq.readonly [| 1; 2 |])[1,2] - Same result as .NET:
seq.delaylet mutable n = 0 in let s = Seq.delay (fun () -> n <- n + 1; Seq.singleton n) in string n + "," + Ji s0,[1]
Maps, sets and dictionaries48 / 50 same as .NET
- Same result as .NET:
map.sorted.keysJ (m () |> Map.toList |> List.map kv)[1=a,2=b,3=c] - Same result as .NET:
map.string.keysJ (Map.ofList [ "b", "1"; "B", "2"; "a", "3" ] |> Map.toList |> List.map kv)[B=2,a=3,b=1] - Same result as .NET:
map.findMap.find 2 (m ()) + "," + (m ()).[3]b,c - Same result as .NET:
map.find.missingMap.find 9 (m ())EXN KeyNotFound - Same result as .NET:
map.tryfindstring (Map.tryFind 9 (m ())) + "," + string (Map.tryFind 1 (m ())),Some(a) - Same result as .NET:
map.add.replaceJ (m () |> Map.add 1 "z" |> Map.add 0 "y" |> Map.toList |> List.map kv)[0=y,1=z,2=b,3=c] - Same result as .NET:
map.removeJ (m () |> Map.remove 2 |> Map.remove 9 |> Map.toList |> List.map kv)[1=a,3=c] - Same result as .NET:
map.countstring (Map.count (m ())) + "," + string (m ()).Count + "," + B (Map.isEmpty Map.empty)3,3,true - Same result as .NET:
map.containskeyB (Map.containsKey 1 (m ())) + "," + B ((m ()).ContainsKey 7)true,false - Same result as .NET:
map.foldMap.fold (fun s k v -> s + string k + v) "" (m ())1a2b3c - Same result as .NET:
map.foldbackMap.foldBack (fun k v s -> s + string k + v) (m ()) ""3c2b1a - Same result as .NET:
map.map.filterJ (m () |> Map.filter (fun k _ -> k > 1) |> Map.map (fun k v -> v + v) |> Map.toList |> List.map kv)[2=bb,3=cc] - Same result as .NET:
map.changeJ (m () |> Map.change 1 (Option.map (fun v -> v + "!")) |> Map.change 5 (fun _ -> Some "e") |> Map.toList |> List.map kv)[1=a!,2=b,3=c,5=e] - Same result as .NET:
map.equalityB (Map.ofList [ 1, "a"; 2, "b" ] = Map.ofList [ 2, "b"; 1, "a" ])true - Same result as .NET:
map.comparestring (compare (Map.ofList [ 1, "a" ]) (Map.ofList [ 1, "b" ]))-1 - Same result as .NET:
map.tuple.keysJ (Map.ofList [ (2, "a"), "x"; (1, "b"), "y"; (1, "a"), "z" ] |> Map.toList |> List.map snd)[z,y,x] - Same result as .NET:
map.record.keysstring (Map.count (Map.ofList [ Some 1, "a"; Some 1, "b"; None, "c" ]))2 - Same result as .NET:
map.minkeystring (Map.minKeyValue (m ()) |> fst) + "," + string (Map.maxKeyValue (m ()) |> fst)1,3 - Same result as .NET:
map.keys.valuesJi (m ()).Keys + J (m ()).Values[1,2,3][a,b,c] - Same result as .NET:
map.partitionlet a, b = Map.partition (fun k _ -> k % 2 = 1) (m ()) in string a.Count + string b.Count21 - Same result as .NET:
map.findkeystring (Map.findKey (fun _ v -> v = "b") (m ()))2 - Same result as .NET:
map.iteratelet mutable s = "" in (for KeyValue (k, v) in m () do s <- s + string k + v); s1a2b3c - Same result as .NET:
set.sortedJi (Set.ofList [ 3; 1; 2; 3 ])[1,2,3] - Same result as .NET:
set.opslet a, b = set [ 1; 2; 3 ], set [ 2; 3; 4 ] in Ji (Set.union a b) + Ji (Set.intersect a b) + Ji (Set.difference a b)[1,2,3,4][2,3][1] - Same result as .NET:
set.subsetB (Set.isSubset (set [ 1 ]) (set [ 1; 2 ])) + "," + B (Set.isProperSuperset (set [ 1 ]) (set [ 1 ]))true,false - Same result as .NET:
set.containsB (Set.contains 2 (set [ 1; 2 ])) + "," + string (Set.count (set [ "a"; "a" ]))true,1 - Same result as .NET:
set.equalityB (set [ 1; 2 ] = set [ 2; 1 ]) + "," + string (compare (set [ 1; 2 ]) (set [ 1; 3 ]))true,-1 - Same result as .NET:
set.minmaxstring (Set.minElement (set [ 5; 2; 8 ])) + "," + string (Set.maxElement (set [ 5; 2; 8 ]))2,8 - Same result as .NET:
set.tuplesJ (Set.ofList [ (2, "a"); (1, "b"); (1, "a") ] |> Seq.map (fun (a, b) -> string a + b))[1a,1b,2a] - Same result as .NET:
set.removeJi (Set.remove 2 (set [ 1; 2; 3 ]))[1,3] - Same result as .NET:
dictionary.orderlet d = Dictionary<string, int>() in d.["b"] <- 1; d.["a"] <- 2; d.["c"] <- 3; J (d.Keys |> Seq.map id)[b,a,c] - Same result as .NET:
dictionary.missinglet d = Dictionary<int, int>() in string d.[5]EXN KeyNotFound - Same result as .NET:
dictionary.add.duplicatelet d = Dictionary<int, int>() in d.Add(1, 1); d.Add(1, 2); "added"EXN Argument - Same result as .NET:
dictionary.trygetvaluelet d = dict [ 1, "a" ] in match d.TryGetValue 1 with | true, v -> v | _ -> "none"a - Same result as .NET:
dictionary.trygetvalue.missinglet d = Dictionary<int, string>() in match d.TryGetValue 1 with | true, v -> v | _, v -> "none:" + string (isNull v)none:True - Same result as .NET:
dictionary.removelet d = Dictionary<int, int>() in d.[1] <- 1; B (d.Remove 1) + B (d.Remove 1) + string d.Counttruefalse0 - Same result as .NET:
dictionary.tuple.keylet d = Dictionary<int * string, int>() in d.[(1, "a")] <- 5; string d.[(1, "a")]5 - Known difference:
dictionary.union.keylet d = Dictionary<int option, int>() in d.[Some 1] <- 5; d.[None] <- 6; string d.[Some 1] + string d.[None].NETEXN ArgumentNullJS56 - Different result:
dictionary.readonly.dictlet d = dict [ 1, "a" ] in try d.[2] <- "b"; "set" with e -> "EXN".NETEXNJSset - Same result as .NET:
dictionary.kvpJ (Dictionary(dict [ 1, "x"; 2, "y" ]) |> Seq.map (fun kv -> string kv.Key + kv.Value))[1x,2y] - Same result as .NET:
readonlydictlet d = readOnlyDict [ "a", 1 ] in string d.["a"] + "," + string d.Count1,1 - Same result as .NET:
hashsetlet h = HashSet<int>([ 3; 1; 3 ]) in B (h.Add 1) + B (h.Add 2) + string h.Count + Ji hfalsetrue3[3,1,2] - Same result as .NET:
hashset.opslet h = HashSet<int>([ 1; 2; 3 ]) in h.IntersectWith [ 2; 3; 4 ]; Ji h[2,3] - Same result as .NET:
hashset.tupleslet h = HashSet<int * int>() in h.Add((1, 2)) |> ignore; B (h.Contains((1, 2)))true - Same result as .NET:
resizearraylet r = ResizeArray [ 1; 2 ] in r.Add 3; r.Insert(0, 0); r.RemoveAt 1; Ji r + string r.Count[0,2,3]3 - Same result as .NET:
resizearray.out.of.rangelet r = ResizeArray [ 1 ] in string r.[3]EXN ArgumentOutOfRange - Same result as .NET:
resizearray.sortlet r = ResizeArray [ 3; 1; 2 ] in r.Sort(); Ji r[1,2,3] - Same result as .NET:
resizearray.modify.during.enumlet r = ResizeArray [ 1; 2 ] in (for x in r do if x = 1 then r.Add 3); string r.CountEXN InvalidOperation - Same result as .NET:
queue.stacklet q = Queue<int>([ 1; 2 ]) in let s = Stack<int>([ 1; 2 ]) in string (q.Dequeue()) + string (s.Pop())12 - Same result as .NET:
queue.emptylet q = Queue<int>() in string (q.Dequeue())EXN InvalidOperation
Records, unions and equality57 / 61 same as .NET
- Same result as .NET:
record.equalityB (p "a" 1 = p "a" 1) + "," + B (p "a" 1 = p "a" 2) + "," + B (obj.ReferenceEquals(p "a" 1, p "a" 1))true,false,false - Same result as .NET:
record.comparisonstring (compare (p "a" 2) (p "b" 1)) + "," + string (compare (p "a" 2) (p "a" 1))-1,1 - Same result as .NET:
record.sortJ ([ p "b" 1; p "a" 2; p "a" 1 ] |> List.sort |> List.map (fun x -> x.Name + string x.Age))[a1,a2,b1] - Same result as .NET:
record.hashB (hash (p "a" 1) = hash (p "a" 1))true - Same result as .NET:
record.copy.updatelet a = p "a" 1 in let b = { a with Age = 5 } in string a.Age + string b.Age15 - Same result as .NET:
record.distinctstring (List.length (List.distinct [ p "a" 1; p "a" 1; p "b" 1 ]))2 - Same result as .NET:
record.setstring (Set.count (set [ p "a" 1; p "a" 1 ]))1 - Same result as .NET:
record.dictionary.keylet d = Dictionary<Person, int>() in d.[p "a" 1] <- 1; d.[p "a" 1] <- 2; string d.Count + string d.[p "a" 1]12 - Same result as .NET:
record.hashsetlet h = HashSet<Person>() in h.Add(p "a" 1) |> ignore; B (h.Add(p "a" 1))false - Same result as .NET:
record.custom.equalityB ({ Key = "k"; Note = "1" } = { Key = "k"; Note = "2" })true - Same result as .NET:
record.custom.dictionarylet d = Dictionary<Loose, int>() in d.[{ Key = "k"; Note = "1" }] <- 1; string d.[{ Key = "k"; Note = "2" }]1 - Same result as .NET:
record.mutable.fieldlet m = { Count = 0 } in m.Count <- m.Count + 2; string m.Count2 - Same result as .NET:
record.mutable.aliaslet m = { Count = 0 } in let n = m in n.Count <- 3; string m.Count3 - Same result as .NET:
record.struct.copylet a = { X = 1; Y = 2 } in let b = { a with X = 5 } in string a.X + string b.X + B (a = { X = 1; Y = 2 })15true - Same result as .NET:
record.struct.comparestring (compare { X = 1; Y = 2 } { X = 1; Y = 3 })-1 - Same result as .NET:
record.anonymouslet a = {| A = 1; B = "x" |} in string a.A + a.B + B (a = {| A = 1; B = "x" |})1xtrue - Same result as .NET:
record.anonymous.copylet a = {| A = 1; B = "x" |} in let b = {| a with A = 2 |} in string b.A + b.B2x - Same result as .NET:
record.anonymous.nestedlet x = { Inner = {| A = 1; B = "b" |} } in x.Inner.Bb - Same result as .NET:
union.equalityB (Circle 1.0 = Circle 1.0) + "," + B (Circle 1.0 = Rect (1.0, 1.0)) + "," + B (Empty = Empty)true,false,true - Same result as .NET:
union.comparisonstring (sign (compare (Circle 5.0) (Rect (1.0, 1.0)))) + "," + string (sign (compare Empty (Circle 0.0))) + "," + string (sign (compare (Rect (1.0, 2.0)) (Rect (1.0, 1.0))))-1,1,1 - Same result as .NET:
union.sortstring (List.sort [ Empty; Rect (1.0, 1.0); Circle 2.0; Circle 1.0 ] |> List.map (function Circle r -> "C" + string r | Rect _ -> "R" | Empty -> "E") |> String.concat "")C1C2RE - Same result as .NET:
union.hashB (hash (Rect (1.0, 2.0)) = hash (Rect (1.0, 2.0)))true - Same result as .NET:
union.matchJ ([ Circle 1.0; Rect (2.0, 3.0); Empty ] |> List.map (function Circle r -> string (r * 2.0) | Rect (w, h) -> string (w * h) | Empty -> "-"))[2,6,-] - Same result as .NET:
union.named.fieldsmatch Rect (h = 2.0, w = 3.0) with Rect (w = w) -> string w | _ -> "?"3 - Same result as .NET:
union.recursivestring (sum (Node (Node (Leaf, 1, Leaf), 2, Node (Leaf, 3, Leaf))))6 - Same result as .NET:
union.structB (SA 1 = SA 1) + "," + string (compare (SA 5) (SB "a")) + "," + (match SB "z" with SB b -> b | SA _ -> "?")true,-1,z - Same result as .NET:
union.single.caselet (Wrapper w) = Wrapper 5 in string w + B (Wrapper 1 < Wrapper 2)5true - Same result as .NET:
union.isCaseB (Circle 1.0).IsCircle + "," + B Empty.IsRecttrue,false - Same result as .NET:
union.map.keylet m = Map.ofList [ Rect (1.0, 1.0), "r"; Empty, "e"; Circle 1.0, "c" ] in J (Map.toList m |> List.map snd)[c,r,e] - Same result as .NET:
option.equalityB (Some 1 = Some 1) + "," + B (None = (None: int option)) + "," + string (compare None (Some 1))true,true,-1 - Same result as .NET:
option.functionsstring (Option.map ((+) 1) (Some 1)) + "," + string (Option.defaultValue 9 None) + "," + string (Option.bind (fun x -> if x > 0 then Some x else None) (Some -1))Some(2),9, - Same result as .NET:
option.value.nonestring (Option.get (None: int option))EXN Argument - Known difference:
option.value.propstring (None: int option).Value.NETEXN NullReferenceJSEXN Exception - Same result as .NET:
option.isnoneB (Option.isNone None) + "," + B (Some 1).IsSometrue,true - Same result as .NET:
option.tolistJi (Option.toList (Some 3)) + "," + string (Option.count None)[3],0 - Same result as .NET:
option.nullB (obj.ReferenceEquals(None, null))true - Same result as .NET:
option.ofobjstring (Option.ofObj (null: string)) + "," + string (Option.ofObj "x"),Some(x) - Same result as .NET:
voptionlet v = ValueSome 3 in string (ValueOption.defaultValue 0 v) + B (ValueNone = (ValueNone: int voption))3true - Known difference:
resultlet r : Result<int, string> = Ok 1 in string (Result.map ((+) 1) r) + "," + string (Result.bind (fun _ -> Error "e") r : Result<int, string>).NETMicrosoft.FSharp.Core.FSharpResult`2[System.Int32,System.String],Microsoft.FSharp.Core.FSharpResult`2[System.Int32,System.String]JS[object Object],[object Object] - Same result as .NET:
result.matchmatch (Error "bad" : Result<int, string>) with Ok v -> string v | Error e -> ebad - Same result as .NET:
result.equalityB ((Ok 1 : Result<int, string>) = Ok 1) + "," + string (compare (Ok 1 : Result<int, int>) (Error 0))true,-1 - Same result as .NET:
tuple.equalityB ((1, "a") = (1, "a")) + "," + string (compare (1, "b") (1, "a")) + "," + string (compare (2, "a") (10, "a"))true,1,-1 - Same result as .NET:
tuple.structlet struct (a, b) = struct (1, "x") in string a + b1x - Same result as .NET:
tuple.fst.sndstring (fst (1, 2)) + string (snd (1, 2))12 - Same result as .NET:
enum.tostringstring Color.Green + "," + string (int Color.Blue)Green,4 - Same result as .NET:
enum.flags.tostringstring (Color.Red ||| Color.Blue)5 - Same result as .NET:
enum.of.intstring (enum<Color> 2) + "," + string (enum<Color> 3)Green,3 - Same result as .NET:
enum.tostring.methodColor.Blue.ToString() + "|" + string (enum<Color> 42) + "|" + string DayOfWeek.SundayBlue|42|Sunday - Same result as .NET:
enum.flags.namesstring (Perm.Read ||| Perm.Write) + "|" + string Perm.None + "|" + (Perm.Exec).ToString() + "|" + string (enum<Perm> 8)Read, Write|None|Exec|8 - Same result as .NET:
enum.hasflagB ((Color.Red ||| Color.Blue).HasFlag Color.Blue)true - Same result as .NET:
enum.compareB (Color.Red < Color.Blue) + "," + string (compare Color.Blue Color.Green)true,1 - Known difference:
enum.parsestring (Enum.Parse(typeof<Color>, "Blue") :?> Color).NETBlueJScompile error: not supported - Same result as .NET:
unit.equalityB (() = ())true - Same result as .NET:
structural.nestedB ([ Some (p "a" 1, [| 1 |]) ] = [ Some (p "a" 1, [| 1 |]) ])true - Same result as .NET:
physical.equalitylet a = p "a" 1 in B (LanguagePrimitives.PhysicalEquality a a) + "," + B (LanguagePrimitives.PhysicalEquality a (p "a" 1))true,false - Same result as .NET:
compare.mixed.stringsJ (List.sort [ "a"; "B"; "_"; "1"; "é" ])[1,B,_,a,é] - Same result as .NET:
compare.floats.nan.sortJ (List.sort [ 2.0; nan; 1.0 ] |> List.map string)[NaN,1,2] - Same result as .NET:
compare.charstring (compare 'a' 'B')1 - Same result as .NET:
hash.string.stableB (hash "abc" = hash ("ab" + "c"))true - Same result as .NET:
hash.intstring (hash 42) + "," + string (hash -1)42,-1 - Known difference:
equals.boxedB ((box 1).Equals(box 1)) + "," + B ((box 1).Equals(box 1L)) + "," + B (box 1 = box 1.0).NETtrue,false,falseJStrue,false,true
Pattern matching30 / 32 same as .NET
- Same result as .NET:
match.constantmatch n 2 with 1 -> "one" | 2 -> "two" | _ -> "many"two - Same result as .NET:
match.guardmatch n 5 with x when x > 3 -> "big" | _ -> "small"big - Same result as .NET:
match.ormatch n 3 with 1 | 3 | 5 -> "odd" | _ -> "?"odd - Same result as .NET:
match.andmatch (1, 2) with (a, _) & (_, b) -> string (a + b)3 - Same result as .NET:
match.asmatch [ 1; 2 ] with (x :: _) as l -> string x + string l.Length | [] -> ""12 - Same result as .NET:
match.listJ ([ []; [ 1 ]; [ 1; 2 ]; [ 1; 2; 3 ] ] |> List.map (function [] -> "e" | [ a ] -> "1" | [ a; b ] -> "2" | _ :: _ :: rest -> "n" + string rest.Length))[e,1,2,n1] - Same result as .NET:
match.arraymatch [| 1; 2 |] with [| a; b |] -> string (a + b) | _ -> "?"3 - Same result as .NET:
match.tuplematch (n 1, "x") with (1, s) -> s | _ -> "?"x - Same result as .NET:
match.recordmatch { Name = "a"; Age = 3 } with { Age = 3; Name = nm } -> nm | _ -> "?"a - Same result as .NET:
match.option.nestedmatch Some (Some 3) with Some (Some x) -> string x | Some None -> "sn" | None -> "n"3 - Same result as .NET:
match.stringmatch "b" + "c" with "bc" -> "yes" | _ -> "no"yes - Same result as .NET:
match.char.rangematch 'q' with c when c >= 'a' && c <= 'z' -> "lower" | _ -> "?"lower - Same result as .NET:
match.nullmatch (null: string) with null -> "null" | s -> snull - Same result as .NET:
match.typetestJ ([ box 1; box "s"; box [ 1; 2 ]; null; box 1.5 ] |> List.map classify)[int 1,string s,list 2,null,other] - Known difference:
match.typetest.float.intmatch box 2.0 with :? int -> "int" | :? float -> "float" | _ -> "?".NETfloatJSint - Same result as .NET:
match.typetest.int64match box 2L with :? int -> "int" | :? int64 -> "int64" | _ -> "?"int64 - Known difference:
match.typetest.char.stringmatch box 'c' with :? string -> "string" | :? char -> "char" | _ -> "?".NETcharJSstring - Same result as .NET:
match.incompletelet f x = match x with 1 -> "one" in f (n 2)EXN MatchFailure - Same result as .NET:
match.active.totalJ ([ 1; 2 ] |> List.map (function Even -> "even" | Odd -> "odd"))[odd,even] - Same result as .NET:
match.active.partialmatch "42" with Int v -> string (v + 1) | _ -> "nan"43 - Same result as .NET:
match.active.structmatch n 5 with Positive v -> string v | _ -> "no"5 - Same result as .NET:
match.active.paramJ (List.map fizz [ 3; 5; 15; 7 ])[Fizz,Buzz,FizzBuzz,7] - Same result as .NET:
match.active.singlelet (Lower s) = "ABC" in sabc - Same result as .NET:
match.functionlet f = function Some x -> x | None -> 0 in string (f (Some 4) + f None)4 - Same result as .NET:
match.let.tuplelet a, (b, c) = 1, (2, 3) in string (a + b + c)6 - Same result as .NET:
match.wildcard.lambdaJi (List.map (fun (_, b) -> b) [ (1, 2); (3, 4) ])[2,4] - Same result as .NET:
match.cons.string.listmatch [ "a"; "b" ] with h :: t -> h + string t.Length | [] -> ""a1 - Same result as .NET:
match.enummatch Color.Green with Color.Red -> "r" | Color.Green -> "g" | _ -> "?"g - Same result as .NET:
match.enum.undefinedmatch enum<Color> 7 with Color.Red -> "r" | _ -> "other"other - Same result as .NET:
match.union.nestedmatch Node (Leaf, 1, Node (Leaf, 2, Leaf)) with Node (_, _, Node (_, v, _)) -> string v | _ -> "?"2 - Same result as .NET:
match.exceptiontry raise (ArgumentException "x") with :? ArgumentException as e -> "arg" | _ -> "other"arg - Same result as .NET:
match.kvpmatch KeyValuePair(1, "a") with KeyValue (k, v) -> string k + v1a
Language54 / 62 same as .NET
- Same result as .NET:
closure.capturelet fs = [ for i in 1 .. 3 -> fun () -> i ] in Ji (List.map (fun f -> f ()) fs)[1,2,3] - Same result as .NET:
closure.mutable.reflet r = ref 0 in let f () = r.Value <- r.Value + 1 in f (); f (); string r.Value2 - Same result as .NET:
closure.loop.mutablelet fs = ResizeArray() in (for i in 0 .. 2 do fs.Add(fun () -> i * 10)); Ji (fs |> Seq.map (fun f -> f ()))[0,10,20] - Same result as .NET:
curryinglet f = curry 1 in let g = f 2 in string (g 3)123 - Same result as .NET:
compositionlet f = ((+) 1) >> ((*) 2) in let g = ((+) 1) << ((*) 2) in string (f 3) + "," + string (g 3)8,7 - Same result as .NET:
pipesstring ((1, 2) ||> (+)) + "," + string ((1, 2, 3) |||> fun a b c -> a + b + c)3,6 - Same result as .NET:
recursionstring (fact 10) + "," + B (even 11)3628800,false - Same result as .NET:
tail.recursion.deepstring (loop 0 1000000)1000000 - Known difference:
recursion.deep.nontaillet rec f n = if n = 0 then 0 else 1 + f (n - 1) in string (f 10000).NET10000JSEXN Exception - Same result as .NET:
string.of.genericshow true + "|" + show (null: string) + "|" + show 4True||4 - Not supported:
inline.srtpstring (twice 3) + "," + twice "ab" + "," + string (twice 1.5).NET6,abab,3JScompile error: not supported - Same result as .NET:
generic.functionstring (List.length (generic 1)) + J (generic "a")2[a,a] - Same result as .NET:
mutable.looplet mutable s = 0 in (for i in 1 .. 10 do s <- s + i); string s55 - Same result as .NET:
for.downtolet mutable s = "" in (for i = 3 downto 1 do s <- s + string i); s321 - Same result as .NET:
while.looplet mutable i = 0 in (while i < 5 do i <- i + 2); string i6 - Same result as .NET:
for.range.steplet mutable s = "" in (for i in 0 .. 5 .. 20 do s <- s + string i + " "); s0 5 10 15 20 - Same result as .NET:
if.unitlet mutable x = 0 in (if n 1 > 0 then x <- 1); string x1 - Same result as .NET:
exception.failwithtry failwith "boom" with Failure m -> "failure:" + mfailure:boom - Same result as .NET:
exception.invalidargtry invalidArg "x" "bad" with :? ArgumentException as e -> e.ParamNamex - Same result as .NET:
exception.argument.message(ArgumentException("bad", "x")).Message + "|" + (try invalidArg "y" "worse" with e -> e.Message)bad (Parameter 'x')|worse (Parameter 'y') - Same result as .NET:
exception.failure.subclasstry raise (InvalidOperationException "op") with Failure m -> "failure:" + m | e -> "other"other - Same result as .NET:
exception.invalidoptry invalidOp "nope" with :? InvalidOperationException as e -> e.Messagenope - Same result as .NET:
exception.customtry raise (MyError ("m", 7)) with MyError (s, i) -> s + string im7 - Same result as .NET:
exception.reraisetry (try failwith "inner" with _ -> reraise ()) with e -> e.Messageinner - Same result as .NET:
exception.finallylet mutable log = "" in (try (try failwith "x" finally log <- log + "F") with _ -> log <- log + "C"); logFC - Same result as .NET:
exception.message.divisiontry string (1 / n 0) with e -> e.MessageAttempted to divide by zero. - Known difference:
exception.nullreflet s : string = null in string s.Length.NETEXN NullReferenceJSEXN Exception - Same result as .NET:
exception.tostring(ArgumentException "x").Messagex - Same result as .NET:
exception.innerlet e = Exception("outer", Exception "inner") in e.InnerException.Messageinner - Same result as .NET:
use.disposelet log = ResizeArray() in (using (new Disposable(log)) (fun _ -> log.Add "body")); J log[body,disposed] - Same result as .NET:
use.bindinglet log = ResizeArray() in let f () = (use d = new Disposable(log) in log.Add "body") in f (); J log[body,disposed] - Same result as .NET:
class.memberslet c = Counter() in c.Incr() |> ignore; c.Incr() |> ignore; c.Count <- c.Count * 10; string c.Count20 - Different result:
class.static.letlet before = Counter.Created in Counter() |> ignore; string (Counter.Created - before).NET1JS0 - Same result as .NET:
inheritancelet d = Dog "Rex" :> Animal in d.Speak()Rex barks; Rex makes a sound - Same result as .NET:
inheritance.tostringstring (Dog "Rex")Animal Rex - Same result as .NET:
object.expressionlet s = shape "sq" 2.0 in s.Name + string (s.Area())sq2 - Not supported:
object.expression.overridelet o = { new Object() with override _.ToString() = "custom" } in string o.NETcustomJScompile error: not supported - Same result as .NET:
interface.castlet o = shape "x" 1.0 in match box o with :? IShape as s -> s.Name | _ -> "no"x - Different result:
interface.cast.faillet o = box (Counter()) in try (o :?> IShape).Name with :? InvalidCastException -> "cast".NETcastJS<null> - Different result:
downcast.faillet o = box "s" in try string (unbox<int> o) with :? InvalidCastException -> "cast".NETcastJSs - Same result as .NET:
operator.overloadstring (Vec(1.0, 2.0) + 2.0 * Vec(1.0, 1.0))(3,4) - Same result as .NET:
method.overloadlet o = Overloads() in o.F(1) + o.F("s") + o.F(1, 2)intstringtwo - Same result as .NET:
optional.argslet o = Overloads() in string (o.G 1) + "," + string (o.G(1, 2))11,3 - Same result as .NET:
named.argslet o = Overloads() in string (o.G(y = 5, x = 1))6 - Same result as .NET:
lazylet mutable n = 0 in let l = lazy (n <- n + 1; n) in string l.Value + string l.Value + B l.IsValueCreated11true - Same result as .NET:
lazy.exceptionlet l = lazy (failwith "lz" : int) in let a = (try string l.Value with e -> e.Message) in a + "," + (try string l.Value with e -> e.Message)lz,lz - Same result as .NET:
computation.optionstring (maybe { let! a = Some 1 in let! b = Some 2 in return a + b }) + "," + string (maybe { let! a = None in return a + 1 })Some(3), - Same result as .NET:
units.of.measurestring (3.0<M> * 2.0)6 - Same result as .NET:
ref.celllet r = ref "a" in r.Value <- r.Value + "b"; r.Valueab - Same result as .NET:
byreflet mutable x = 1 in bump &x; string x2 - Same result as .NET:
shadowinglet x = 1 in let x = x + 1 in string x2 - Same result as .NET:
tuple.returnlet divrem a b = a / b, a % b in let q, r = divrem 17 5 in string q + string r32 - Same result as .NET:
outref.tryparselet ok, v = Double.TryParse "2.5" in B ok + string vtrue2.5 - Same result as .NET:
id.ignoreignore (n 5); string (id 3)3 - Same result as .NET:
nameofnameof Counter + "," + nameof nCounter,n - Known difference:
typeof.nametypeof<int>.Name.NETInt32JScompile error: not supported - Same result as .NET:
box.unboxlet o = box 3 in string (unbox<int> o + 1)4 - Same result as .NET:
isnullB (isNull (null: string)) + "," + B (isNull (box 0))true,false - Same result as .NET:
default.valuesstring (Unchecked.defaultof<int>) + "," + B (isNull (Unchecked.defaultof<string>)) + "," + string (Unchecked.defaultof<float>)0,true,0 - Same result as .NET:
eventlet e = Event<int>() in let mutable s = 0 in e.Publish.Add(fun x -> s <- s + x); e.Trigger 2; e.Trigger 3; string s5 - Same result as .NET:
delegatelet d = Func<int, int>(fun x -> x * 3) in string (d.Invoke 4)12 - Same result as .NET:
action.delegatelet mutable s = "" in let a = Action<string>(fun x -> s <- s + x) in a.Invoke "x"; a.Invoke "y"; sxy
Dates, math and conversions38 / 47 same as .NET
- Same result as .NET:
datetime.partslet x = d () in string x.Year + "," + string x.Month + "," + string x.Day + "," + string x.Hour + "," + string x.Minute + "," + string x.Second2024,2,29,13,45,30 - Same result as .NET:
datetime.dayofweekstring (d ()).DayOfWeek + "," + string (d ()).DayOfYearThursday,60 - Same result as .NET:
datetime.adddays(d ()).AddDays(1.0).ToString("yyyy-MM-dd")2024-03-01 - Same result as .NET:
datetime.addmonths(d ()).AddMonths(12).ToString("yyyy-MM-dd")2025-02-28 - Same result as .NET:
datetime.addyears(d ()).AddYears(1).ToString("yyyy-MM-dd")2025-02-28 - Same result as .NET:
datetime.format.custom(d ()).ToString("yyyy-MM-dd HH:mm:ss")2024-02-29 13:45:30 - Known difference:
datetime.format.iso(d ()).ToString("o").NET2024-02-29T13:45:30.0000000JS2024-02-29T13:45:30.0000000+00:00 - Known difference:
datetime.tostringstring (d ()).NET02/29/2024 13:45:30JS2/29/2024, 1:45:30 PM - Same result as .NET:
datetime.subtractstring (DateTime(2024, 3, 1) - DateTime(2024, 2, 1)).TotalDays29 - Same result as .NET:
datetime.compareB (d () < (d ()).AddSeconds 1.0) + "," + B (d () = DateTime(2024, 2, 29, 13, 45, 30))true,true - Same result as .NET:
datetime.daysinmonthstring (DateTime.DaysInMonth(2024, 2)) + "," + B (DateTime.IsLeapYear 1900)29,false - Same result as .NET:
datetime.parse(DateTime.Parse "2024-01-15T10:00:00").ToString("yyyy-MM-dd HH:mm")2024-01-15 10:00 - Same result as .NET:
datetime.date(d ()).Date.ToString("HH:mm")00:00 - Same result as .NET:
datetime.invalidstring (DateTime(2023, 2, 29)).DayEXN ArgumentOutOfRange - Same result as .NET:
datetime.invalid.timetry string (DateTime(2024, 1, 1, 24, 0, 0)).Hour with :? ArgumentOutOfRangeException -> "range"range - Same result as .NET:
datetime.minvaluestring DateTime.MinValue.Year + "," + string DateTime.MaxValue.Year1,9999 - Same result as .NET:
datetime.ticksstring (DateTime(2000, 1, 1)).Ticks630822816000000000 - Not supported:
datetimeoffsetlet x = DateTimeOffset(2024, 1, 1, 0, 0, 0, TimeSpan.Zero) in string (x.ToUnixTimeSeconds()).NET1704067200JScompile error: not supported - Same result as .NET:
timespan.partslet t = TimeSpan(1, 2, 3, 4) in string t.Days + "," + string t.Hours + "," + string t.TotalMinutes1,2,1563.0666666666666 - Different result:
timespan.tostringstring (TimeSpan(1, 2, 3, 4)) + "|" + string (TimeSpan.FromMinutes 90.5).NET1.02:03:04|01:30:30JS93784000|5430000 - Different result:
timespan.negativestring (TimeSpan.FromSeconds -61.0).NET-00:01:01JS-61000 - Same result as .NET:
timespan.arithstring (TimeSpan.FromHours 1.0 + TimeSpan.FromMinutes 30.0).TotalHours1.5 - Same result as .NET:
timespan.comparestring (compare (TimeSpan.FromSeconds 1.0) (TimeSpan.FromSeconds 2.0))-1 - Same result as .NET:
guid.parsestring (Guid.Parse "6F9619FF-8B86-D011-B42D-00CF4FC964FF")6f9619ff-8b86-d011-b42d-00cf4fc964ff - Same result as .NET:
guid.emptystring Guid.Empty00000000-0000-0000-0000-000000000000 - Same result as .NET:
guid.equalityB (Guid.Parse "6f9619ff-8b86-d011-b42d-00cf4fc964ff" = Guid.Parse "6F9619FF-8B86-D011-B42D-00CF4FC964FF")true - Same result as .NET:
guid.newguid.uniqueB (Guid.NewGuid() <> Guid.NewGuid())true - Same result as .NET:
char.parsestring (Char.Parse "x") + "," + string (Char.GetNumericValue '7')x,7 - Same result as .NET:
char.tostring.intstring (int (Char.MaxValue))65535 - Same result as .NET:
bool.parsestring (Boolean.Parse "True") + "," + string (Boolean.Parse "false")True,False - Same result as .NET:
nullablelet x = Nullable 3 in let y = Nullable<int>() in string x.Value + "," + B y.HasValue + "," + string (y.GetValueOrDefault 9)3,false,9 - Same result as .NET:
math.functionsstring (Math.Max(3, 7)) + "," + string (Math.Abs -2.5) + "," + string (Math.Floor -1.5) + "," + string (Math.Sign -3)7,2.5,-2,-1 - Same result as .NET:
math.constantsstring (Math.Round(Math.PI, 4)) + "," + string (Math.Round(Math.E, 4))3.1416,2.7183 - Same result as .NET:
math.clampstring (Math.Clamp(15, 0, 10))10 - Same result as .NET:
math.divremlet q, r = Math.DivRem(17, 5) in string q + string r32 - Same result as .NET:
math.truncate.logstring (Math.Truncate -2.9) + "," + string (Math.Log10 1000.0) + "," + string (Math.Log(8.0, 2.0))-2,3,3 - Same result as .NET:
convert.tobaseConvert.ToString(10, 2) + "," + string (Convert.ToInt32("ff", 16))1010,255 - Same result as .NET:
convert.toint32.roundingstring (Convert.ToInt32 2.5) + "," + string (Convert.ToInt32 3.5)2,4 - Same result as .NET:
convert.base64Convert.ToBase64String [| 1uy; 2uy; 255uy |]AQL/ - Same result as .NET:
convert.frombase64Ji (Convert.FromBase64String "AQL/" |> Array.map int)[1,2,255] - Same result as .NET:
convert.todoublestring (Convert.ToDouble 2.5) + "," + string (Convert.ToSingle 1.5)2.5,1.5 - Same result as .NET:
convert.toint32.basestring (Convert.ToInt32("-12", 10)) + "," + string (Convert.ToInt32("ffffffff", 16)) + "," + Convert.ToString(-1, 16)-12,-1,ffffffff - Not supported:
bitconverterstring (BitConverter.GetBytes(1).Length).NET4JScompile error: not supported - Same result as .NET:
random.rangelet r = Random() in let x = r.Next(5, 10) in B (x >= 5 && x < 10)true - Not supported:
urilet u = Uri "https://example.com:8080/a/b?q=1" in u.Host + "," + string u.Port + "," + u.AbsolutePath.NETexample.com,8080,/a/bJScompile error: not supported - Known difference:
typeof.int.nametypeof<string>.FullName.NETSystem.StringJScompile error: not supported - Known difference:
gettype.name(box 1).GetType().Name.NETInt32JScompile error: not supported
How this is computed
The cases live in WebSharper's own repository (tests/WebSharper.FSharp.Conformance). The same F# project is built for .NET and with WebSharper, run on .NET and under Node, and the outputs are compared. The check runs on every release build against a committed baseline, so a change that makes any case worse fails the build.
- Same as .NET: JavaScript prints exactly what .NET prints.
- Known difference: an accepted difference that follows from JavaScript, listed above with its alternative.
- Mismatch: a different result with no accepted reason, a bug to fix.
For tools and AI agents
The results are published as JSON: every case with its F# source, its .NET output and its status, and the known differences with their reasons and alternatives.
Whether an API translates at all is a separate question: see API coverage.