Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Last active January 20, 2017 08:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save puffnfresh/5b144ac191d8a9dccb6766ae40e9ab17 to your computer and use it in GitHub Desktop.
Save puffnfresh/5b144ac191d8a9dccb6766ae40e9ab17 to your computer and use it in GitHub Desktop.
declare namespace F {
class Either<A, B> {
private constructor();
// Hack to make A and B covariant.
private a: A;
private b: B;
static Left<A, B>(a: A): Either<A, B>;
static Right<A, B>(b: B): Either<A, B>;
static either<A, B, C>(f: (a: A) => C, g: (b: B) => C, e: Either<A, B>): C;
static of<A, B>(b: B): Either<A, B>;
static isLeft<A, B>(e: Either<A, B>): boolean;
static isRight<A, B>(e: Either<A, B>): boolean;
map<C>(f: (b: B) => C): Either<A, C>;
chain<C>(f: (b: B) => Either<A, C>): Either<A, C>;
bimap<C, D>(f: (a: A) => C, g: (b: B) => D): Either<C, D>;
equals(e: Either<A, B>): boolean;
}
}
declare module 'ramda-fantasy' {
export = F;
}
@srijs
Copy link

srijs commented Jan 20, 2017

The example you gave:

const x: F.Either<{}, number> = F.Either.Right<{}, string>('wat')

doesn't compile for me, even after removing the private variables.

It does compile however after removing the methods on the class, since then the rules of structural equivalence ignore the two generics due to them not being part of the structure itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment