Closed yongqli closed 9 years ago
I'm assuming you mean the analog to the list last
function. I don't see how you can do last
in O(1). Even head
and tail
are O(n). If you can implement it, I'd certainly consider a pull request.
Hmm, I guess we can't pattern match on the last snoc
, so it's not possible with this definition.
Since a DList
is represented as a function, primarily to get the “free” append via function composition, it is really a “one-way” type for collecting a bunch of appends and dealing them out in the end when you want to reconstruct the desired list. Thus, most of the DList
functions that provide access to elements of the implied list are really convenience functions on top of toList
.
You may be interested in Data.Sequence
for its O(1) viewr
.
It should be possible to access last in
O(1)
.