Continuing the discussion of this previous topic Deep copy or shallow copy? - #8 by lydell
I would like to understand why, in the following code, the lazy function viewSubTree
works despite the facts that a structure created on the fly is passed to the lazy function (the variable tree
)
-- A tree structure
type Tree n
= Tree
{ node : n
, children : List (Tree n)
}
-- convert a dict to a tree structure
buildTree : NodesDict -> Tree Node
[...]
-- A function that display a tree selector
viewSelectorTree : (Node -> msg) -> GqlData (Dict string Node) -> Html msg
viewSelectorTree onTargetClick odata =
case odata of
Success data ->
let
tree =
buildTree data
in
div [ id "tree-selector", class "menu" ] [ Lazy.lazy2 viewSubTree onTargetClick tree ]
_ ->
div [ class "spinner" ] []
Understanding why this works could hopefully help us predict when a lazy function will be defeated and when it won’t, I believe.