In a small bowl, mix together ricotta cheese, rosemary and black pepper. Place half of the potato-onion mixture in a 13 x 9-inch baking dish and top this with the ricotta cheese and ham strips. Cover with the remaining potatoes. Pour the milk over the entire casserole. Bake for 1 1/2 hours, or until the potatoes are soft and the sauce is thick and bubbly.
Top with the grated cheese and bake for 15 to 20 minutes more, or until the cheese melts.