4 ms·
Self-Memoizing HTML Rendering via Mutually Recursive Data Types
- munro 12y agoNice optimization for rerendering HTML, I wonder if React uses this technique. Also, sometimes I wonder if it's worth pulling out separate concepts from a data structure ... I usually just embed them, but I always consider building a parallel data structure. data HTML = Text String | Element String [HTML] data MemoizedHTML = MemoizedText String | MemoizedElement String [MemoizedHTML] rendered :: (HTML, MemoizedHTML) rendered = ( Element "foo" [ Element "bar" [], Text "hello" ], MemoizedElement "<foo><bar />hello</foo>" [ MemoizedElement "<bar />" [], MemoizedText "hello" ] )
- amelius 12y agoLook here [1] for a generalization of this idea. [1] http://www.umut-acar.org/self-adjusting-computation http://www.umut-acar.org/self-adjusting-computation
- edem 12y agoPlease add the programming language used at the top. I looked at the code and it was obvious that it was not java/lisp/python/php (the ones I know). I guessed Haskell and I had to do a text search to find it out.