Code Monkey home page Code Monkey logo

Comments (5)

treeowl avatar treeowl commented on July 16, 2024

One request: since this will be a somewhat invasive fix, I'd like to have enough time to finish the digit size experiment first, to avoid a difficult merge.

from containers.

foxik avatar foxik commented on July 16, 2024

The Word is Haskell 2010, so why not.

Nevertheless, I am not sure that performing run-time checks is the right way to go (because of efficiency). Another way to tacke this could be using Word64 and specifying that all representable sequences can have at most 2^64 elements. Wait -- that would mean that the index type would be Word64, which is a big API change.

This also casts shadow on the Word size -- does it mean the index will use Word as index type? If so, I think it is not worth it.

from containers.

treeowl avatar treeowl commented on July 16, 2024

Word64 is pretty bad in 32-bit code, and also could be quite bad for an implementation using pointer tagging, so I don't think we want that. index isn't a big deal. That can stay as it is and get converted to a Word. There just might be elements that can't be reached by index. It might pay to add a Word-based indexing function alongside. About the same thing goes for length, except that in this case the length function would have to check the range.

Yes, you could "solve" the range problem for repeated appends by specifying that it's prohibited, but silently giving wrong answers when someone does something wrong doesn't really seem like the Haskell way. Most people seem to think such runtime checks usually get predicted correctly and have minimal cost, but some benchmarks would be required to see.

from containers.

foxik avatar foxik commented on July 16, 2024

If index is using Int on the outside, I am not sure whether it is worth it changing the internal representation to Word, as the observable size type will still be Int. Thit probably applies to length even more.

I understand that silent bugs and failures are very bad. I am just not sure what the overhead will be, so as you say, we should look at the benchmarks. BTW, note that similar silent failures will happen with Map and Set larger than Int -- the Int size field will overflow, causing rotations to stop working correctly, cause wrong results of size, elemAt etc. With the Map and Set, we are neverless reasonably sure that such large structures will not exist (as creating such structures requires a huge amount of memory), which is not the case for replicate.

from containers.

treeowl avatar treeowl commented on July 16, 2024

I think you may (sadly) be right about the Word thing. But I also realized that a 32-bit implementation using tagging could have a problem using Int for sizes. Just something to keep in mind; not necessarily something to do anything about right now.

The overflow tests should be cheap under GHC, I believe, as I believe it offers primops giving access to hardware overflow flags. But yes, benchmarking required.

from containers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.