Lesson 17 of 55
9 mins readPython Function Composition (.) & Application ($)
In Plain English
Compose functions mathematically with the dot operator (.): (f . g) x = f (g x). Use the low-precedence application operator ($) to eliminate cluttering parentheses.
Deep Dive: How It Works
Composition (.): (f . g) x evaluates g x first, then feeds the result to f.
Application ($): f $ x is simply f x, but $ has the lowest possible precedence, meaning putStrLn $ "Hello " ++ "World" avoids surrounding parentheses.
Point-Free Style: Writing functions without mentioning the input variable names (e.g. fn = sum . map (^2) . filter even).
Core Rules to Remember

Mathematical Composition (.): Chains pipeline stages together into a single new function.

Dollar Operator ($): Replaces trailing closing parentheses for clean readable code.
Live Interactive Example
Hit Run Code to see it livePoint-Free Composition and Dollar Operator
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
Output Console
Click "Run Code" to view the rendered output.
How it works: sumEvenSquares filters evens, squares them, and sums them in a point-free pipeline.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Compose Double and Successor
Define `f = (* 2) . (+ 1)`.
Evaluate `f 4` and print `"Result: "` followed by `show (f 4)`.
1
2
3
4
5
6
7
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.