Show and tell: Build Connections puzzle game

I’ve been using my first deep dive into Rescript and React to build a clone of the NYT Connections puzzle which allows setting custom puzzles: Build Connections (source)

Here’s an FP themed puzzle for you.

I use Vue (+ typescript) professionally, and I’ve been on an FP journey since discovering Elm a few years ago. Elm is still my yardstick for language design, and I haven’t yet found another language that comes close for DX and overall ecosystem niceness. But its strict purity with awkward effect management and FFI had me shopping around for different experiences. Besides Elm I’ve worked with Haskell and Purescript. I had never tried React, but had long had my eye on Rescript as a way of breaking into that whole world.

I particularly enjoyed using JSX (with one caveat :wink:), and the ease of hooking into JS and the React ecosystem. Also, though I really appreciate pure FP and managed effects for large-scale type safety, for a project of this size it’s refreshing to just do side effects without worrying about any conceptual overhead, while still benefiting from immutability, pattern matching and all the other FP goodies. I thought I’d miss function composition, but honestly it’s kind of nice not to have that option (I can get carried away with point-free at times). Pipe-first also wasn’t that hard to get used to, and I particularly like placeholder arguments, which pretty much overshadow my fondness for the conceptual elegance of currying. And I looove polymorphic variants, especially when I found how useful they are for error handling—and they map nicely to Typescript literal types.

My greatest struggle was with the package ecosystem, especially when it comes to JS bindings. I was struck by the lack of Rescript packages offering bindings for even the most core tools such as React Router. I made heavy use of framer-motion for animations, transitions and drag’n’drop—and loved it—but I frequently felt like I was back in untyped JS land, having to comb through the docs to figure out how to use (and subsequently type) some functionality, when I’m so used to the types just guiding. The same went for unit testing. I gave up writing tests for my React components (for now) because I really couldn’t figure out if the required Rescript packages exist and work properly. (I will ask for help about that in a separate thread.)

Similarly I find the Belt standard library a bit jaunty, with a lot of standard immutable functions on arrays missing. For example, I ended up implementing Array.sort as List.fromArray >> List.sort >> List.toArray (maybe I missed a better way). Probably one good reason for missing immutable functions is the fact that they’re operating on plain JS arrays rather than a performant persistent data structure. But that makes me wonder if JS arrays are dragging Rescript down a bit…

I’m still to get to grips with module functors (though I have a vague sense that they could be really powerful). The nice thing is that, unlike the dreaded Monad in Haskell, you can still be very productive (and build a complete puzzle game) while barely thinking about this more advanced concept.

Overall I’ll probably keep Rescript in mind for future projects, and I’m also encouraged to give Ocaml a try. It’s been a fun journey—thanks to the Rescript team!

2 Likes

Heyy I play this every morning, really well done clone! :clap:

Similarly I find the Belt standard library a bit jaunty, with a lot of standard immutable functions on arrays missing. For example, I ended up implementing Array.sort as List.fromArray >> List.sort >> List.toArray (maybe I missed a better way).

I think the stdlib thing is one of those old sore spots that’s really hard to remove. Did you by chance see @rescript/core? It’s an official new stdlib that provides better bindings for most native JS functions + some goodies for option and result. For the immutable sort I would do Array.copy(x)->Array.sort which I think translates to x.slice().sort()

Ahh, I hadn’t, thanks for that! And glad I’ve found a Connections fan! It’s really fun to make puzzles tailored to people you know, include in-jokes, etc.