6.001 SICP 1 Normal (Lazy) Order Evaluation Memoization Streams.
Memoization & HOF
-
Upload
surendra-shukla -
Category
Documents
-
view
25 -
download
0
Transcript of Memoization & HOF
HOF & MemoizationSurendra Shukla
HOF (Higher Order Function) & Memoization Page 2
• Memoization–Memoizing result
• HOF (Higher Order Functions)– Partial Application• Partial Left• Partial Right• Partial Any
–Currying
Topics
HOF (Higher Order Function) & Memoization Page 3
• Functions can use objects to remember the results of previous operations.
• This optimization is called memoization.• Objects and arrays are very convenient for this.
Memoization
HOF (Higher Order Function) & Memoization Page 4
• In mathematics and computer science, a higher-order function is a function that does at least one of the following: • Takes one or more functions as an input • Outputs a function
• E.g.: h(x) = f(g(x));
HOF (Higher Order Function)
HOF (Higher Order Function) & Memoization Page 5
• Allows you to apply a function partially, What this means is that, • You have a function that takes more than one parameter.• You pass it fewer parameters than it wants,
– and it returns a new function.• That will take the remaining parameters
– and it returns a result.
• E.g.: f: X * Y -> R
• f`: Y -> R – (X × Y → R) × X) → (Y → R)
HOF – Partial Application / Partially applied functions
HOF (Higher Order Function) & Memoization Page 6
• Currying is the technique of:• Translating the evaluation of a function that takes multiple
arguments (or a tuple of arguments) • Into evaluating a sequence of functions, each with a single
argument (partial application)
• E.g.: (X × Y → R) → (X → (Y → R))
• h (x, y, z) = f(x)(y)(z);
HOF – Currying
THANKS
Page 7