How does Haskell deal with large data structures that need small modification?

So in Haskell you cannot modify things. If you need to insert something into a tree you have to construct a new Tree. However if you have a large tree then creating a new tree just to insert one element seems to be wasteful. In 'learnyouhaskell', I read that laziness takes care of this? How? I am looking for an in-depth answer.

Edit: Hey everyone thanks for all the answers. Though I did not understand all of it. I guess the main point is that they 'behave as if they are permanent and immutable' as tejon put it. My primary programming language is C, also I have been programming in python for some time. I have started learning haskell seriously about a month ago. So my thought process is still very imperative. I guess I will have to learn much more and code a lot before attempting to understand what happens under the hood.

Posted Feb 17, 2017, 3:49 AM UTC · edited

17
Loading comments…