From a45d737a7b069dfb779d65491a9e7fa9763de463 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Mon, 6 Aug 2018 23:18:32 +0000 Subject: [PATCH] matching on objects with lower-case first letters --- puzzlers/pzzlr-072.html | 70 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 puzzlers/pzzlr-072.html diff --git a/puzzlers/pzzlr-072.html b/puzzlers/pzzlr-072.html new file mode 100644 index 0000000..8464ce7 --- /dev/null +++ b/puzzlers/pzzlr-072.html @@ -0,0 +1,70 @@ +

Matching on objects with lower-case first letters

+ + + + + + + + + + + + + + + + +
Contributed byRyan Williams, Martijn Hoekstra
Sourcescala/scala Gitter
First tested with Scala version2.12.6
+
+

What is the result of executing the following code?

+
+sealed trait obj
+case object one extends obj
+case object two extends obj
+def test(o: obj) =
+  o match {
+    case one ⇒ 1
+    case two ⇒ 2
+  }
+println(test(one))
+println(test(two))
+
+
    + +
  1. prints "1" and then "2"
  2. +
  3. throws MatchError
  4. +
  5. prints "1" and then "1"
  6. +
  7. compile error
  8. +
+
+ +