Created
October 4, 2017 10:02
-
-
Save abiodun0/0d3059fda410d42a94abbe125b2a9194 to your computer and use it in GitHub Desktop.
Problems with ts
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
// Typescript can handle monomoprhic functions | |
const flip = <A, B, C>(f: (a: A) => (b: B) => C): ((b: B) => (a: A) => C) => b => a => f(a)(b) | |
const foo = (a: string) => (b: number) => a.length - b | |
// fooFlipped: (b: number) => (a: string) => number | |
const fooFlipped = flip(foo) | |
// But can't handle polymorphic functions | |
const concat = <A>(xs: Array<A>) => (a: A): Array<A> => xs.concat([a]) | |
// concatFlipped: (b: {}) => (a: {}) => {}[] | |
const concatFlipped = flip(concat) | |
// ok but is awkward | |
const concatFlipped2: <A>(a: A) => (xs: Array<A>) => Array<A> = flip(concat) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment