Without knowing the type of fan you are talking about this question can be difficult. I'll assume you mean an AC ceiling fan.
The wall switch is utilizing solid state device called a triac. This device will allow current to pass through it in only one direction at a time (the direction is controlled by a gate voltage).
in your wall switch the gate of the triac is hooked up to a basic series RC circuit. The knob controls a variable resistance which changes the RC time constant for the voltage on the capacitor. Once the voltage is past the gate's minimum turn on voltage the triac will conduct current.
In short a triac is simply opening and closing the circuit to provide a lesser voltage to the wall socket.
Now for the ceiling fan:
The ceiling fan is an AC motor (ill assume you know how those work) whose positive armature is connected to one of n leads (n being the number of fan speeds). Each one of these N fan speeds is connected across a resistor, with the leads decreasing from full 120V to 0V (or whatever the voltage of the motor is).
So in this instance the fan is supplied with a full 120V and is then the extra energy is dissipated in the form of heat through the resistors.
Long story short the dimmer switch limits the voltage by turning on at specific times in the AC cycle while the fan does it by dissipating the voltage through a resistor.