efficient list append/prepend through function composition

↘锁芯ラ 提交于 2019-12-07 01:03:11

问题


Some months ago I read somewhere of an efficient approach for appending and prepending lists to other lists in O(1) by representing them with function compositions that, once evaluated, build in O(n) the resulting list.

Unfortunately I cannot remember the source of this article or (if existing) the name of this technique/approach. Do you have references about it, please?


回答1:


The data structure is called a difference list (or DList for short). You can find a default implementation of it in a library available on Hackage.

As you mentioned, a full description can be gathered from a chapter in Real World Haskell on the subject.




回答2:


You must be thinking of ShowS and friends from the Prelude. See here.



来源:https://stackoverflow.com/questions/11329660/efficient-list-append-prepend-through-function-composition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!