Grease a medium casserole.
Arrange a third of potatoes in bottom of the dish.
Scatter with half the onion and half the flour, a generous sprinkling of salt, pepper and cheese.
Repeat this arrangement, then cover with remaining potatoes.
Sprinkle with salt, pepper, cheese and dab with margarine.
Pour in milk until it is visible through the top layer of potatoes.
Bake covered at 350F (180C) for 35 minutes.
Uncover and bake until potatoes are tender and top is browned, about 25 minutes.