A Theory of Duality for Algebraic Curves