What is the role of detergent and softener respectively?
Detergent is just as its name implies, has produced under the condition of scale (usually the Ca+Mg+ cation is solid by precipitation), pickling methods such as precipitation to restore the soluble, easy to remove.
The main function of water softener is to remove Ca+Mg+ and other cations in water to prevent precipitation.
Water containing more cations such as Ca+Mg+ becomes "hard water", and these ions are temporarily dissolved in water, but are easily combined with OH-, CO3 and other anions in the case of heating