That cannot happen in an immutable world. To fill an empty cup, you cons a cup and its contents. To get an empty cup again, you take the car of the cons. The full cup will only get garbage collected if you do not reference it anymore.
That simply has the wrong type in mathematically civilized languages like Standard ML or Haskell.
> The full cup will only get garbage collected if you do not reference it anymore.
This is orthogonal to functional programming. You can avoid the need for a garbage collector with substructural types.
1. Apply a quantum permutation to your list.
2. Check if it's sorted.
3. If not, destroy the universe.
Fortunately, we don't have any currently promising avenues for nucleating a true vacuum or anything like that, so this algorithm is purely theoretical.
For now.
https://en.wikipedia.org/wiki/Quarantine_%28Greg_Egan_novel%...
In all good text books this is left as an exercise for the reader.
Bogosort is O(n) in the best case and O(inf) in the worst case).
If you want to replace a leg, you still need to disassemble the chair and reassemble it with new screws.
While going about your work, you suddenly disappear along with your universe and everything in it. Someone somewhere in the world drank a cup of coffee, which means that he now has an empty cup instead of a full cup. A new universe had to be created with the full cup replaced, and unfortunately your universe had to be thrown away. You continue life as a clone in a new universe with an empty coffee cup somewhere in Nebraska.
Why did this happen? Someone picked a copy-on-write map implementation because it had a slightly faster O(logN) delete behavior and unfortunately the re-use function of the map wasn't implemented yet because the author has gone on to do a series on the use of monads in baking the ultimate croissant.