Uncategorized

Control Abstraction

  • Reducing code duplication
    • higher-order functions are functions which take functions as parameters and are better for simplifying code
  • Currying
    • A curried function is applied to multiple argument lists, instead of just one:
      • eg. normal method: def normalSum(num1: Int, num2: Int) = num1 + num2
      • eg. curried method: def plainOldSum(x: Int, y: Int) = x + y What’s happening here is that when you invoke curriedSum, you actually get two traditional function invocations back to back. The first function invocation takes a single Int parameter named x, and returns a function value for the second function. This second function takes the Int parameter y
  • Writing new control structures
    • In languages with first-class functions, you can effectively make new control structures even though the syntax of the language is fixed. All you need to do is create methods that take functions as arguments
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s