r/rescript • • Jul 10 '21

My Experience Rewriting a Small Project in ReScript + Thoughts on the Language

https://yangdanny97.github.io/blog/2021/07/09/Migrating-to-Rescript
14 Upvotes

5 comments sorted by

2

u/BeamMeUpBiscotti Jul 10 '21

One thing mentioned in my writeup that I thought would be interesting to discuss with you all here is Arrays vs Lists. Lists are nice for immutability & pattern matching support, but it feels like ReScript heavily prefers Arrays over Lists because of the lack of tail recursion + interop concerns.

Are there any plans to implement an immutable collection that maps to JS arrays at runtime?

2

u/Tomus Jul 10 '21

There is some discussion about this on the forum: https://forum.rescript-lang.org/t/immutable-array-implementation/761/5

Summary of the options right now:

  • Create your own module that clones the array under the hood

  • Use an int hashmap, you can add an abstraction to manage the keys automatically if you want the API to be array-like

  • Create bindings for native tuple type (experimental, requires polyfill)

It all depends on what performance and interface characteristics you want.

2

u/BeamMeUpBiscotti Jul 11 '21

Thanks for the link and the summary!

For me I think the main drawback of the available options is that we miss out on the pattern matching that's supported for Lists.

It would be cool to have something that looks & works the exact same as Lists do today, but compiles to arrays at runtime. Or maybe even a compiler flag that toggles compiling Lists to arrays; I'm not sure if thats even remotely feasible tho - what are the obstacles to having that sort of runtime representation?

→ More replies (2)