News for hackers. Stuff that matters.
Re:New Features in C# 7.0 by lacampbell on Thursday March 09, 2017 @07:35PM (#13835274)
Your ShapeHandler example above is an example of multiple dispatch[1] - something not very fashionable anymore, but which I'd love to see in a statically typed language. It's a more natural feature for an OO language - but I wonder about the trade offs it has with pattern matching and Algebraic Data Types.

[1] http://wiki.c2.com/?MultipleDispatch

Re:New Features in C# 7.0 by MaulingMonkey on Saturday March 11, 2017 @01:16AM (#13844490)
FWIW you can abuse dynamic in C# to get multiple dispatch, although not with much static checking.

  using System;
  
  class Foo { }
  class Bar { }
  
  static class Program {
  	static void Example(Foo l, Foo r) { Console.WriteLine("Foo Foo"); }
  	static void Example(Foo l, Bar r) { Console.WriteLine("Foo Bar"); }
  	static void Example(Bar l, Foo r) { Console.WriteLine("Bar Foo"); }
  	static void Example(Bar l, Bar r) { Console.WriteLine("Bar Bar"); }
  
  	static object Create(string arg) { return arg == "Foo" ? (object)new Foo() : new Bar(); }
  
  	static void Main(string[] args) {
  		dynamic l = Create(args.Length > 0 ? args[0] : "Foo");
  		dynamic r = Create(args.Length > 1 ? args[1] : "Bar");
  		Example(l, r);
  	}
  }