Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maybe make a traverse test #24

Open
Anton-Latukha opened this issue Nov 21, 2021 · 6 comments
Open

Maybe make a traverse test #24

Anton-Latukha opened this issue Nov 21, 2021 · 6 comments

Comments

@Anton-Latukha
Copy link
Contributor

Anton-Latukha commented Nov 21, 2021

traverse pure probably suitable to be used for data structure spine traversal "in the data-type-recommended way".

Maybe there even more idiomatic way to do it.

Maybe traverse (const $ Identity ()) would ensure nudging Haskell to not manipulating, maybe even not looking into values at all.

As I am interested to see how data structure spine traversing goes in which data types to understand the impact of the design of data structures on spine traversal & so fold.

@Anton-Latukha
Copy link
Contributor Author

Anton-Latukha commented Nov 22, 2021

Length is kinda a spine traversal test, but length :: Foldable t => t a -> Int does not guarantee the real traversal of datatype happening, does traversal happens depends on datatype design & how instance Foldable Type length is optimally retrieved (for example type can store its size or even num of elems literally), length does not guarantee traversal.

@Anton-Latukha
Copy link
Contributor Author

Anton-Latukha commented Nov 22, 2021

Also, afaiu Min & Max benchmarks are mostly also mirroring a traverse benchmark. So having a clean representation of traverse would be informative & {Length,Max,Min} are additional benchmarks of particular information getters.

@chrisdone
Copy link
Member

I think length is a good benchmark by itself, because Seq etc do indeed track length, but DList/Acc don't, which costs Seq extra constant factors, but wins when calling length. Asking for the size of something is definitely a good test in its own right.

For traversals... I'm not sure how worth it that is. Often times the function being ran will have more overhead than the traversal itself. But feel free to come up with an interesting test. 👌

@Anton-Latukha
Copy link
Contributor Author

Anton-Latukha commented Nov 22, 2021

Yes, since I like folds & traversals & between the two - traversal would be the most direct test of data type spine traverse. With laziness,
const should ensure Haskell that the value in the cell should not be looked into. I believe something like void or Identity should be cheap.

If only nomeata/ghc-heap-view#36 merged so ghc-vis was able to update to support new compilers - then it would've been easy to just observe traversal. If I could literally look it in ghc-vis - I'd submitted it right now, but otherwise, I need to appeal to the word of an authority & believe that something traverses only the data type spine.

BTW this may be useful in checking the benchmarks also: https://www.youtube.com/watch?v=I4lnCG18TaY

@chrisdone
Copy link
Member

You should use IO to do the traversal if anything. I think Identity would be equivalent to calling map, because GHC sees that it's just a newtype wrapper.

@Anton-Latukha
Copy link
Contributor Author

Ok. I would look into traverse somewhere along the line 🤣.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants