The notions of density, thinness, residue and ideal in a free monoid can al
l be expressed in terms of the infix order. Guided by these definitions we
introduce the same notions with respect to arbitrary binary relations. We t
hen investigate properties of these generalized notions and explore the con
nection to the theory of codes. We show that, under certain assumptions abo
ut the relation, density is preserved by an endomorphism or the inverse of
an endomorphism if and only if - essentially - the endomorphism induces a p
ermutation of the generators of the free monoid.