Notes: - Abstraction over explicit instructions - More compact - Easy to read, even for non-SQL Users
Notes: - Combine 2 or more functions into a new function - Evaluation done via substitution

Basic FP Building Blocks

  • Higher-Order Function
    • Function that takes another function as input or returns a function as result
  • Function Composition
    • Combines 2 or more functions into a new function
    • (a -> b) -> (b -> c) -> (a -> c)
  • Partial Application
    • Call function with less parameters than expected
    • Returns a function taking the rest or result

Type Signatures

  • As per lambda calculus
    • Function takes in single parameter
    • Returns result or partially applied function
  • Concrete types are capitalized
  • Parameterized types are lowercase
  • Optional Type Constraints come before => symbol

Type Classes

  • Similar to interfaces in OOP
    • Defines behaviour
    • Types implement that behaviour
  • Much more powerful
    • Instances implemented separately from type definitions
    • Can be added to any type (including base types)
    • Allows multiple type parameters

Number of Possible Implementations of Function?

  • a -> a
    • identity
  • a -> b
    • None
  • (a, a) -> a
    • fst
    • snd
  • (a -> b) -> [a] -> [b]
    • map
  • Num a => a -> a -> a
    • Infinite combinations of +, -, *
Notes: - Since the type signature is (possibly) so closely linked to the implementation, the type signature alone allows us to find existing implementations.