Skip to content

Instantly share code, notes, and snippets.

@53ningen
Last active August 29, 2015 14:27
Show Gist options
  • Save 53ningen/ed2ee7ae8c59e33c50e0 to your computer and use it in GitHub Desktop.
Save 53ningen/ed2ee7ae8c59e33c50e0 to your computer and use it in GitHub Desktop.

2. getting started

2.1 次を実装せよ

def curry[A, B, C, D](f: (A, B, C) => D): A => B => C => D = ???

def uncurry[A, B, C, D](f: A => B => C => D): (A, B, C) => D = ???

def compose[A, B, C, D](f: A => B, g: B => C, h: C => D): A => D = ???

answer

def curry[A, B, C, D](f: (A, B, C) => D): A => B => C => D = {
  a => b => c => f(a, b, c)
}

def uncurry[A, B, C, D](f: A => B => C => D): (A, B, C) => D = {
  (a, b, c) => f(a)(b)(c)
}

def compose[A, B, C, D](f: A => B, g: B => C, h: C => D): A => D = {
  compose(compose(f, g), h)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment