Yes, this would be interesting.
I'm not aware there is any such thing, though, and midi data is by implication strictly sequential. I'm not aware of any way such a function could be inserted into a midi stream.
If I had the time to do something, for my particular purposes (which may be quite different to yours), I would look at two possibilities.
Firstly, write a (or more likely amend an existing) program that takes pre-defined midi phrases and builds a midi file which can then be played, the program allowing loops.
Secondly, I could add refinements to my own midi file player, which stores the midi data in a way of my own design, so that after an existing midi file has been loaded in, then loops could be added. As it's my own prog, and I can amend it any way I choose, I could add my own commands into the data to, for example, loop back from the current point to a previous point.
?? possibly allowing some variation to the loop - i.e. play the loop, then replay with all the notes raised by xx semitones?
This is something I have thought about for my own purposes. Just never got around to doing anything.
Please say a bit more about exactly what you were hoping to do.
Geoff