Last active
April 8, 2016 21:37
-
-
Save danclien/9adc6d20dc88d28c05e90df4e3f05719 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// data Foo = Bar Int | Baz String | |
public abstract class Foo | |
{ | |
public sealed class Bar : Foo | |
{ | |
public int Value { get; set; } | |
} | |
public sealed class Baz : Foo | |
{ | |
public string Value { get; set; } | |
} | |
public T Fold<T>(Func<Bar, T> barFunc, Func<Baz, T> bazFunc) | |
{ | |
if (this is Bar) | |
{ | |
return barFunc((Bar) this); | |
} | |
else if (this is Baz) | |
{ | |
return bazFunc((Baz) this); | |
} | |
else | |
{ | |
throw new Exception("Oops"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment