Two steps to deriving a generic algorithm