Skip to content
ExamRizzInterview readingReading
Leave

STEM · Computer Science · Foundational Concepts/Principles

Save

Functional Programming Concepts

Significance: FP treats computation as evaluation of functions, avoiding mutable state and side effects. Key concepts: first-class functions (functions as values), higher-order functions (functions taking/returning functions), immutability, recursion, lambda expressions. Enables reasoning about correctness, parallelization. Languages: Haskell, Lisp, ML, Erlang; features in JavaScript, Python, Java, C++.

Questions to think through

  1. Apply higher-order functions: Implement `map`, `filter`, `reduce`. Map applies function to each element: `map(f, [1,2,3])` → `[f(1), f(2), f(3)]`. Filter selects elements: `filter(even, [1,2,3,4])` → `[2,4]`. Reduce combines: `reduce(+, [1,2,3,4])` → `10`. Write these using recursion and lambda expressions. Explain why these are powerful: express complex operations compositionally (e.g., `reduce(+, filter(even, map(square, nums)))`).

    explain
  2. Understand immutability: In imperative code, `x = x + 1` mutates x. In functional code, create new value. Example: `append([1,2], [3,4])` returns new list `[1,2,3,4]` without modifying originals. Explain advantages: (a) thread-safety (no race conditions) (b) easier reasoning (values don't change) (c) time-travel debugging (keep old versions). Disadvantages: (a) memory overhead (b) copying cost. How do persistent data structures (structural sharing) mitigate costs?

    explain

Functional Programming · Higher-Order Functions · Immutability · Lambda Expressions · Recursion · Haskell