Friday, 15 July 2011

dom - What haskell data structure to store mutable tree -



dom - What haskell data structure to store mutable tree -

i thinking writing browser in haskell. central info construction mutable tree representing document. apart using tree composing exclusively of iorefs, there improve solution?

i hoping avoid this: data domnode = domnode tagname nodeproperties (ioref domnode) [ioref domnode] (tag, properties, parent, children)

the problem javascript can hold onto references of nodes in tree, , can mutate (add children, modify properties) node has reference to, traverse it's parent.

edit:

i realized need utilize mutable state somehow - because can hold onto reference node deleted tree, or moved in tree. if referred element via based on construction of tree, reference invalid.

it natural javascript operate mutable references, you'll have introduce them sooner or later (not iorefs, maybe kind of lookup table living in state monad).

if of operations on dom performed javascript, improve select info construction natural it.

don't seek utilize pure info construction purity itself. otherwise you'll finish hand-made emulation of ram :) task looks imperative me, why not utilize imperative features haskell provides?

i don't think zippers, niklas b. suggested, can help lot. have 1 "cursor", can mutate. (afaik in theory number of cursors possible, in practice unusable)

dom haskell data-structures tree

No comments:

Post a Comment