Last active
January 16, 2017 19:10
-
-
Save mlhaufe/5d5a098cb6cae372ee7f7e89c4c8a031 to your computer and use it in GitHub Desktop.
Coproducts
This file contains 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 Either a b = Left a | Right b | |
abstract class Either<A, B> { | |
constructor(public value: A | B) { } | |
} | |
// Inject Left | |
// inl a | |
class Left<A> extends Either<A, never>{ | |
constructor(value: A) { super(value) } | |
} | |
// Inject Right | |
// inr a | |
class Right<B> extends Either<never, B>{ | |
constructor(value: B){ super(value) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment