[Haskell-cafe] tree insert and laziness
Semen Trygubenko / Семен Тригубенко
semen at trygub.com
Sat Aug 16 21:05:30 UTC 2014
I'm presently reviewing a translation of the following paragraph
(taken from LUaH, chapter 8):
"In languages like C, we'd do this by modifying the pointers
and values inside the tree. In Haskell, we can't really modify our tree,
so we have to make a new sub-tree each time we decide to go left
or right and in the end the insertion function returns a completely new tree,
because Haskell doesn't really have a concept of pointer, just values.
Hence, the type for our insertion function is going
to be something like a -> Tree a - > Tree a. It takes an element and a tree
and returns a new tree that has that element inside.
This might seem like it's inefficient but laziness takes care of that
If it is really the laziness that makes this approach efficient?
If it isn't, what did the author want to say in the last sentence?
Семен Тригубенко http://trygub.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 196 bytes
Desc: not available
More information about the Haskell-Cafe