I am new to Functional programming.
The challenge I have is regarding the mental map of how a binary search tree works in Haskell.
- In other programs (C,C++) we have something called root. We store it in a variable. We insert elements into it and do balancing etc..
- The program takes a break does other things (may be process user inputs, create threads) and then figures out it needs to insert a new element in the already created tree. It knows the root (stored as a variable) and invokes the insert function with the root and the new value.
So far so good in other languages. But how do I mimic such a thing in Haskell, i.e.
- I see functions implementing converting a list to a Binary Tree, inserting a value etc.. That's all good
- I want this functionality to be part of a bigger program and so i need to know what the root is so that i can use it to insert it again. Is that possible? If so how?
Note: Is it not possible at all because data structures are immutable and so we cannot use the root at all to insert something. in such a case how is the above situation handled in Haskell?
root
member of the instance gets changed. – Hightension