Skip to content

Instantly share code, notes, and snippets.

@jakewitcher
Last active March 1, 2020 03:10
Show Gist options
  • Save jakewitcher/b1e4e1acaceb2e6495811654968dfae4 to your computer and use it in GitHub Desktop.
Save jakewitcher/b1e4e1acaceb2e6495811654968dfae4 to your computer and use it in GitHub Desktop.
Introduction to Type Classes for .NET Developers, Number interface
public interface Number<T>
{
T Add(T a, T b);
T Subtract(T a, T b);
}
public class Integer : Number<int>
{
public int Add(int a, int b) => a + b;
public int Subtract(int a, int b) => a - b;
}
public class Double : Number<double>
{
public double Add(double a, double b) => a + b;
public double Subtract(double a, double b) => a - b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment