Last active
July 30, 2018 00:28
-
-
Save dead-claudia/d38337cfcd5e7b030af2001c22d0c27c to your computer and use it in GitHub Desktop.
Fantasy Land type defs based on https://github.com/Microsoft/TypeScript/issues/17588
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
// A complete set of type defs for Fantasy Land | |
interface Setoid { | |
"fantasy-land/equals"(other: this): boolean; | |
} | |
interface Ord { | |
"fantasy-land/lte"(other: this): boolean; | |
} | |
interface Semigroupoid<A, B> { | |
type F<A, B>: * extends Semigroupoid<A, B>; | |
"fantasy-land/compose"<C>(other: this.F<B, C>): this.F<A, C>; | |
} | |
type CategoryRep<M extends Category<unknown, unknown>> = { | |
"fantasy-land/id"<A>(): M.F<A, A>; | |
}; | |
interface Category<A, B> extends Semigroupoid<A, B> { | |
type F<A, B>: * extends Category<A, B>; | |
constructor: CategoryRep<this>; | |
} | |
interface Semigroup { | |
"fantasy-land/concat"(other: this): this; | |
} | |
type MonoidT<M extends Monoid> = { | |
"fantasy-land/empty"(): M | |
}; | |
interface Monoid extends Semigroup { | |
constructor: MonoidT<this>; | |
} | |
interface Group extends Monoid { | |
"fantasy-land/invert"(): this; | |
} | |
interface Filterable<T> { | |
"fantasy-land/filter"(func: (a: A) => boolean): this; | |
} | |
interface Functor<A> { | |
type T<A>: * extends Functor<A>; | |
"fantasy-land/map"<B>(f: (a: A) => B): this.T<B>; | |
} | |
interface Contravariant<A> { | |
type U<A>: * extends Contravariant<A>; | |
"fantasy-land/contramap"<B>(f: (b: B) => A): this.U<B>; | |
} | |
interface Apply<A> extends Functor<A> { | |
"fantasy-land/ap"<B>(f: this.T<(a: A) => B>): this.T<B>; | |
} | |
type ApplicativeRep<M extends Applicative<unknown>> = { | |
"fantasy-land/of"<A>(a: A): M.T<A>; | |
}; | |
interface Applicative<A> extends Apply<A> { | |
constructor: ApplicativeRep<this>; | |
} | |
interface Alt<A> extends Functor<A> { | |
"fantasy-land/alt"<A>(other: this.T<A>): this.T<A>; | |
} | |
type PlusRep<M extends Plus<unknown>> = { | |
"fantasy-land/zero"<A>(): M.T<A>; | |
}; | |
interface Plus<A> extends Alt<A> { | |
constructor: PlusRep<this>; | |
} | |
interface Alternative<A> extends Applicative<A>, Plus<A> {} | |
interface Foldable<A> { | |
"fantasy-land/reduce"<B>(func: (acc: B, a: A) => B, acc: B): B; | |
} | |
interface Traversable<A> extends Functor<A>, Foldable<A> { | |
"fantasy-land/traverse"<U extends Applicative<B | this.T<B>>, B>( | |
m: ApplicativeRep<U>, func: (a: A) => U.T<B>, | |
): U.T<this.T<B>>; | |
} | |
interface Chain<A> extends Apply<A> { | |
"fantasy-land/chain"<B>(f: (a: A) => this.T<B>): this.T<B>; | |
} | |
type ChainRecRep<M extends ChainRec<unknown>> = { | |
"fantasy-land/chainRec"<A, B, C>( | |
func: (next: (a: A) => C, done: (b: B) => C, acc: A) => M.T<C>, | |
acc: A, | |
): M.T<B>; | |
} | |
interface ChainRec<A> extends Chain<A> { | |
constructor: ChainRecRep<this>; | |
} | |
interface Monad<A> extends Applicative<A>, Chain<A> {} | |
interface Extend<A> { | |
type T<A>: * extends Extend<A>; | |
"fantasy-land/extend"<B>(func: (a: this.T<A>) => B): this.T<B>; | |
} | |
interface Comonad<A> extends Extend<A> { | |
"fantasy-land/extract"(): A; | |
} | |
interface Bifunctor<A, C> extends Functor<C> { | |
type T<B>: this.F<A, B>; | |
type F<A, C>: * extends Bifunctor<A, C>; | |
"fantasy-land/bimap"<B, D>(f: (a: A) => B, g: (c: C) => D): this.T<B, D>; | |
} | |
interface Profunctor<A, C> extends Functor<C> { | |
type T<B>: this.F<A, B>; | |
type F<A, C>: * extends Profunctor<A, C>; | |
"fantasy-land/bimap"<B, D>(f: (a: A) => B, g: (c: C) => D): this.T<A, D>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment