You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because of how ordinary lists are implemented in Haskell, left-associative appending of such lists is very slow. The following takes much more time than it should:
((((l1 ++ l2) ++ l3) ++ l4) ++...)
Optimal appending order is the following:
l1 ++ (l2 ++ (l3 ++ (l4 ++...))))
There's a trick called Difference List which automatically rearranges list appending to get an optimal order. The trick is representing a list in a different way: instead of storing [a], you store [a] -> [a]. It's implemented in the following packages: https://hackage.haskell.org/package/dlist
This technique is very useful if you don't have control of how lists are appending (for example, when appending inside some recursive call).
I thought, that maybe slist package could provide a data type like SDList (similar to DList) — sized difference list to optimize appending. The problem with DList is since it represents the list as a function, you can't get any info from this function for free. With SDList you should be able to store size and get at list size, so I'm thinking about data type like this:
dataSDLista=SDListSize (Slista->Slista)
Do you think it's worth having such a structure in the library? I guess you don't need to implement bazillion functions for this structure at first, it will be enough to have a few basic functions, because mostly you're interested in appending such difference lists and converting from and to Slist.
The text was updated successfully, but these errors were encountered:
Because of how ordinary lists are implemented in Haskell, left-associative appending of such lists is very slow. The following takes much more time than it should:
Optimal appending order is the following:
There's a trick called Difference List which automatically rearranges list appending to get an optimal order. The trick is representing a list in a different way: instead of storing
[a]
, you store[a] -> [a]
. It's implemented in the following packages: https://hackage.haskell.org/package/dlistThis technique is very useful if you don't have control of how lists are appending (for example, when appending inside some recursive call).
I thought, that maybe
slist
package could provide a data type likeSDList
(similar toDList
) — sized difference list to optimize appending. The problem withDList
is since it represents the list as a function, you can't get any info from this function for free. WithSDList
you should be able to store size and get at list size, so I'm thinking about data type like this:Do you think it's worth having such a structure in the library? I guess you don't need to implement bazillion functions for this structure at first, it will be enough to have a few basic functions, because mostly you're interested in appending such difference lists and converting from and to
Slist
.The text was updated successfully, but these errors were encountered: