We define a lattice model for the interaction of a polymer with water. We solve the model in a suitable approximation. In the case of a nonpolar homopolymer, for reasonable values of the parameters, the polymer is found in a noncompact conformation at low temperature; as the temperature grows, there is a sharp transition towards a compact state, then, at higher temperatures, the polymer swells again. This behavior closely reminds one of that of proteins that are unfolded at both low and high temperatures.