Skip to content

Instantly share code, notes, and snippets.

@abiodun0
Created October 4, 2017 10:02
Show Gist options
  • Save abiodun0/0d3059fda410d42a94abbe125b2a9194 to your computer and use it in GitHub Desktop.
Save abiodun0/0d3059fda410d42a94abbe125b2a9194 to your computer and use it in GitHub Desktop.
Problems with ts
// 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