language-specifications

If an identity conversion exists from S to T, must it be that S and T are same type?

陌路散爱 提交于 2021-02-07 05:21:12
问题 In 6.1.6. of the C# language specification, there is: The implicit reference conversions are: (...) From any reference-type to a reference-type T if it has an implicit identity or reference conversion to a reference-type T0 and T0 has an identity conversion to T. Why don't they say instead, more simply: From any reference-type to a reference-type T if it has an implicit identity or reference conversion to T. Is there any factual difference? EDIT: I realized I mistyped the specification and

What is the evaluation order of tuples in Rust?

半世苍凉 提交于 2020-06-14 05:13:33
问题 Tuple elements may have side-effects, and some of them may depend on others. Consider this program: fn main() { let mut v = vec![1, 2]; match (v.pop(), v.pop()) { (Some(z), Some(y)) => println!("y = {}, z = {}", y, z), _ => unreachable!(), } } Does it output y = 1, z = 2 or y = 2, z = 1 ? A few rounds on the Rust Playground suggests the former on stable 1.32.0, but maybe it would change if I ran it more times, recompiled the compiler, changed compiler versions, etc. Is there a documented

What is the evaluation order of tuples in Rust?

≡放荡痞女 提交于 2020-06-14 05:10:31
问题 Tuple elements may have side-effects, and some of them may depend on others. Consider this program: fn main() { let mut v = vec![1, 2]; match (v.pop(), v.pop()) { (Some(z), Some(y)) => println!("y = {}, z = {}", y, z), _ => unreachable!(), } } Does it output y = 1, z = 2 or y = 2, z = 1 ? A few rounds on the Rust Playground suggests the former on stable 1.32.0, but maybe it would change if I ran it more times, recompiled the compiler, changed compiler versions, etc. Is there a documented

Where is it specified whether Unicode identifiers should be allowed in a Haskell implementation?

♀尐吖头ヾ 提交于 2019-12-30 08:14:39
问题 I wanted to write some educational code in Haskell with Unicode characters (non-Latin) in the identifiers. (So that the identifiers look nice and natural for speakers of a natural language other than English which is not using the Latin characters in its writing.) So, I set out for finding an appropriate Haskell implementation that would allow this. But where is this feature specified in the language specification? How would I refer to this feature when looking for a conforming implementation

How to efficiently ensure a decimal value has at least N decimal places

£可爱£侵袭症+ 提交于 2019-12-23 12:27:46
问题 I want to efficiently ensure a decimal value has at least N (=3 in the example below) places, prior to doing arithmetic operations. Obviouly I could format with "0.000######....#" then parse, but it's relatively inefficient and I'm looking for a solution that avoids converting to/from a string. I've tried the following solution: decimal d = 1.23M; d = d + 1.000M - 1; Console.WriteLine("Result = " + d.ToString()); // 1.230 which seems to work for all values <= Decimal.MaxValue - 1 when

Why doesn't an array access expression of a null array reference throw a NullPointerException?

混江龙づ霸主 提交于 2019-12-22 06:36:07
问题 Consider the following code: int[] r = null; r[0] = 1 % 0; I would have expected this to throw a NullPointerException : according to JLS Sec 15.7.1: The left-hand operand of a binary operator appears to be fully evaluated before any part of the right-hand operand is evaluated. = is a binary operator (shown in JLS Sec 15.2 - JLS Sec 15.26 describes assignment operators), and fully-evaluating the left-hand operand will result in a NullPointerException . However, an ArithmeticException is thrown

How to refer to a class when both simple and fully-qualified names clash

依然范特西╮ 提交于 2019-12-21 07:28:50
问题 Consider the following pathological example: class Ideone { static class ArrayList<T> { ArrayList() { System.out.println("!!"); } } static class java { static class util { static class ArrayList<T> { ArrayList() { System.out.println("Here"); } } } } public static void main(String[] args) { new ArrayList<>(); new java.util.ArrayList<>(); // Can I refer to the "usual" java.util.ArrayList? } } The two instances created in the constructor are of the nested classes. But how might I refer to the

Question regarding implicit conversions in the C# language specification

孤街浪徒 提交于 2019-12-20 19:25:10
问题 Section 6.1 Implicit conversions defines an identity conversion thusly: An identity conversion converts from any type to the same type. This conversion exists such that an entity that already has a required type can be said to be convertible to that type. Now, what is the purpose of sentences such as these? (In §6.1.6 Implicit reference conversions) The implicit reference conversions are: [...] From any reference-type to a reference-type T if it has an implicit identity or reference

Question regarding implicit conversions in the C# language specification

余生颓废 提交于 2019-12-20 19:24:03
问题 Section 6.1 Implicit conversions defines an identity conversion thusly: An identity conversion converts from any type to the same type. This conversion exists such that an entity that already has a required type can be said to be convertible to that type. Now, what is the purpose of sentences such as these? (In §6.1.6 Implicit reference conversions) The implicit reference conversions are: [...] From any reference-type to a reference-type T if it has an implicit identity or reference

Operator '==' can't be applied to type T?

别来无恙 提交于 2019-12-19 05:17:59
问题 I thought this method was valid but I was wrong: static void Equals<T>(T x, T y) { return x == y; //operator == can't be applied to type T } After reading the specifiation (§7.2.4 in v3.0 and §7.3.4 in v4.0): 7.2.4 Binary operator overload resolution An operation of the form x op y, where op is an overloadable binary operator, x is an expression of type X, and y is an expression of type Y, is processed as follows: The set of candidate user-defined operators provided by X and Y for the