In a medium saucepan, whisk the flour and milk over medium-high heat until it bubbles and thickens—it will resemble thick, pasty pudding. Stir in the vanilla, scrape it into a bowl and set it aside to cool, with a piece of plastic wrap on the surface to prevent it from getting a skin.
In a large bowl (a stand mixer works well here), beat the butter and sugar for a few minutes, until pale and fluffy. Add the cooled milk mixture in spoonfuls, whipping for a good 5 minutes or so, until the mixture resembles whipped cream. (If the sugar is still a bit grainy, keep on whipping until it isn’t.) If you want chocolate frosting, add the cocoa and whip until it’s well-incorporated.