Code Monkey home page Code Monkey logo

Comments (11)

endobson avatar endobson commented on June 16, 2024

That is because TR's set code was written before mutable sets existed.

Splitting out HashTable might be useful, but I'm not sure if you would want to split out ImmutableHashTable or ReadableHashTable. The first gets you the flat contracts/predicates, the second gets you covariance. Nothing gets you required explicit mutability because you can just revert to HashTable and not specify it.

Sets get more complicated because there are also generic sets which TR still doesn't support.

from typed-racket.

lexi-lambda avatar lexi-lambda commented on June 16, 2024

@shekari Could you explain the typing difference between immutable hash tables and readable hash tables? Why wouldn't they be equivalent?

from typed-racket.

samth avatar samth commented on June 16, 2024

from typed-racket.

lexi-lambda avatar lexi-lambda commented on June 16, 2024

@samth Oh, I see, that makes sense. ImmutableHashTable would still get you covariance, though, yes?

Wouldn't having explicit mutability still be helpful, though? Contracts support it, and then hash-set! and friends would be checked statically rather than at runtime. Though I suppose it wouldn't be backwards-compatible.

from typed-racket.

samth avatar samth commented on June 16, 2024

Yes, all of these things would be good ideas, and I think we could make everything compatible.

from typed-racket.

lexi-lambda avatar lexi-lambda commented on June 16, 2024

Should we fork HashTable into ReadableHashTable, ImmutableHashTable, and MutableHashTable? Then just leave HashTable as-is? It would make HashTable a sort of silly type to use for anything, but I guess that's the price to pay for compatibility.

Then w.r.t. Set, should we make it analogous to the new HashTable types?

from typed-racket.

samth avatar samth commented on June 16, 2024

HashTable would be a supertype of the other types.

I think the story for Set is less obvious. It's not clear that supporting more without supporting generic sets is useful.

from typed-racket.

lexi-lambda avatar lexi-lambda commented on June 16, 2024

With Set, I think we need to at least support mutable hash sets. I ran into this originally when trying to use mutable hash sets in typed code, and the support for them currently simply doesn't exist. Obviously we wouldn't be able to support generic sets, but I think mutable sets are still a pretty valid use case.

from typed-racket.

samth avatar samth commented on June 16, 2024

Sure, if there's need, we should support it. I think we should just split Set and MutableSet though.

from typed-racket.

lexi-lambda avatar lexi-lambda commented on June 16, 2024

You mean make Set and MutableSet entirely disparate types, like Pair and MPair? I think having the type structure of the proposed hash table rework would be nice.

from typed-racket.

lexi-lambda avatar lexi-lambda commented on June 16, 2024

In a perfect world, I think ReadableHashTable would be the supertype (and we could just call it HashTable), and ImmutableHashTable and MutableHashTable would be subtypes. You'd get flat contracts with Immutable, mutability with Mutable, and covariance with Readable and Immutable.

I don't think this is possible while maintaining backwards-compatibility, though. Should we keep HashTable around as a legacy type and add Readable/Immutable/Mutable in parallel?

from typed-racket.

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.