:= F(3) + F(4) end; The function F is nested within E. Note that E's parameter x is visible also in F (as F is a part of E) while both x and y are invisible outside E and F respectively. Similarly, in Standard ML: fun e (x : real) = let fun f y = x+y in f 3 + f 4 end; One way to write the same example in Haskell syntax: e :: Float -> Float e x = f 3 + f 4 where f y = x + y The same example in GNU C syntax (C extended with nested functions): float E(float x) { float F(float y) { return x + y; } return F(3) + F(4); } Quicksort A more realistic example is this implementation of quicksort: void sort(int *items, int size) { void quickSort(int first, int last) { void swap(int p, int q) { int tmp = items[p]; items[p] = items[q]; items[q] = tmp; } int partition() { int pivot = items[first], index = first; swap(index, last); for (int i = first; i < last; i++) if (items[i] < pivot) swap(index++, i); swap(index, last); return index; } if (first < last) { int pivotIndex = partition(); quickSort(first, pivotIndex - 1); quickSort(pivotIndex + 1, last); } } quickSort(0, size - 1); } Another example is the following implementation of the Hoare partition based quicksort using C++11 lambda expression syntax: template<typename RandomAccessIterator> auto Sort(RandomAccessIterator Begin, RandomAccessIterator End)->void { auto Partition = [&]() { //Hoare partition scheme auto &Pivot = *Begin; auto ForwardCursor = Begin; auto BackwardCursor = End - 1; auto PartitionPositionFound = false; auto LocatePartitionPosition = [&]() { while (*ForwardCursor < Pivot) ++ForwardCursor; while (Pivot < *BackwardCursor) --BackwardCursor; if (ForwardCursor >= BackwardCursor) PartitionPositionFound = true; else Swap(*ForwardCursor, *BackwardCursor); }; //Trivial helper function auto MoveOnAndTryAgain = [&]() { ++ForwardCursor; --BackwardCursor; }; //Brief outline of the actual partition process while (true) { LocatePartitionPosition(); if (PartitionPositionFound) return BackwardCursor + 1; else MoveOnAndTryAgain(); } }; //Brief outline of the quicksort algorithm if (Begin < End - 1) { auto PartitionPosition = Partition(); Sort(Begin, PartitionPosition); Sort(PartitionPosition, End); } } Purpose Lexically nested function definitions are a form of information hiding and are useful for dividing procedural tasks into subtasks which are only meaningful locally. This avoids cluttering other parts of the program with functions and variables that are unrelated to those parts. They are typically used as helper