# What's the idiomatic way of using untyped collections/data structures in typed code?

**URL:** <https://racket.discourse.group/t/whats-the-idiomatic-way-of-using-untyped-collections-data-structures-in-typed-code/3958>\
**Category:** Questions & Answers\
**Tags:** typed-racket\
**Created:** [September 27, 2025, 1:36am UTC](https://racket.discourse.group/t/whats-the-idiomatic-way-of-using-untyped-collections-data-structures-in-typed-code/3958 "2025-09-27T01:36:12Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![NoahStoryM](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/noahstorym/32/17_2.png) [@NoahStoryM](https://racket.discourse.group/u/NoahStoryM)\
**Post date:** [September 27, 2025, 2:03am UTC](https://racket.discourse.group/t/whats-the-idiomatic-way-of-using-untyped-collections-data-structures-in-typed-code/3958/2 "2025-09-27T02:03:42Z")

</div>

Hi!

The `data-lib` library contains many mutable data structures, which necessitate distinguishing between read types and write types. While current Typed Racket doesn't provide a built-in way to define such types, we can achieve this through some clever techniques.

You can refer to how I defined [typed-data-queue](https://github.com/NoahStoryM/typed-data-queue/blob/master/data/queue/main.rkt) and [typed-racket-mutable-treelist](https://github.com/NoahStoryM/typed-racket-mutable-treelist/blob/master/racket/mutable-treelist/main.rkt) to implement a similar approach for `typed-data-heap`:

> [@A new way to type mutable data structures with opposite variance in typed racket](https://racket.discourse.group/t/a-new-way-to-type-mutable-data-structures-with-opposite-variance-in-typed-racket/1846):
>
> Hi everyone, I have been experimenting with a way to define types with opposite variance in typed racket (see also [Is it possible to make Mutable Types support subtype? · racket/typed-racket · Discussion #1129 · GitHub](https://github.com/racket/typed-racket/discussions/1129)). The idea is to use a struct with two type arguments, one for the input type and one for the output type, and then use a Parameter type to constrain them. For example, here is how I defined a type for queue, a mutable data structure from data/queue: #lang typed/racket/base (re…

---

_[View the full topic](https://racket.discourse.group/t/whats-the-idiomatic-way-of-using-untyped-collections-data-structures-in-typed-code/3958)._
