Unions between polymorphic variants behind module types
to be able to compose two modules into one (for example, imagine JsonStringCodec and WhateverJsonCodec composed into WhateverStringCodec) so that i can use the one i need and don’t have to chain the...
View ArticleUnions between polymorphic variants behind module types
yeah i figured it’d be complex to implement and it’s a not-so-common scenario (module functions are underrated and underused tbh, they really serve a useful purpose especially with regard to DI). and...
View ArticleAvoiding Obj.magic idioms?
thank you a ton for this, exactly the kind of feedback i was looking for!
View ArticleTuple projection
github.com/ocaml/RFCs Tuple projections ocaml:master ← johnyob:tuple-projections opened 04:15PM - 26 Sep 25 UTC johnyob +251 -0 [Rendered...
View ArticleTuple projection
Just like it in MoonBit, use a.0 to access first component, a.1 to access second component, …
View ArticleTuple projection
I think so. Try https://try.moonbitlang.com/, select 007_basic_tuple.mbt and check “Accessing tuple elements”. Add a line println(tuple.3) and see the magic:
View ArticleTuple projection
i miss this sometimes (fst and snd are deprecated i think). but i usually do tuple destructuring, e.g. let (_, x) = tup. but yes, using .1 would be good (as for named tuple fields, i don’t really care...
View ArticleAvoiding Obj.magic idioms?
You can make your own versions of Obj.magic that have more restrictions when necessary: type t external coerce: 'a => t = "%identity" Or only coerce after verification: let rawCode: unknown =...
View Article[RFC] @unboxed NaN and infinities
There’s nothing technically preventing this from being possible to implement at least. Other than that, I don’t really have an opinion.
View ArticleTuple projection
you can indeed define records that compile to arrays in rescript, that’s a nice way to replace tuples with something more ergonomic: type t = { @as("0") foo: int, @as("1") bar: string } let t = { foo:...
View ArticleBest practice developer copilot rules for React?
I can’t seem to edit my answer, so posting my recent list here again: You use the latest ReScript v12 rc. Ensure suggestions match this version. Refer to the indexed ReScript manual. Ensure any...
View ArticleBinding to Postgres.js — sharing experience
Hello there, After a long pause I want to give ReScript a try on backend of an app I’m working on. One required aspect is a PostgreSQL database access. Previously I had experience with it using Knex...
View ArticleBinding to Postgres.js — sharing experience
Now about some observations of where ReScript might be improved for better DX Properly bind with @taggedTemplate Currently the @taggedTemplate works correctly only for functions with two arguments....
View ArticleBinding to Postgres.js — sharing experience
Sorry to hijack the thread, but a side note and not entirely on topic: pgtyped-rescript exists if you’re interested in raw Postgres SQL with type safety in ReScript: GitHub - zth/pgtyped-rescript:...
View ArticleBinding to Postgres.js — sharing experience
Thanks for pointing out! I saw pgtyped-rescript when I was looking around. TBH, I was confused by it a little because I have no if the SQL parser works properly not only for simple CRUD-requests, but...
View ArticleBinding to Postgres.js — sharing experience
It uses the actual database to get types, so for the flat regular rows it handles them very well, regardless of how complicated the query is (since it’s the db that can tell you what the return types...
View ArticleImmutable to Mutable Record type
Is there a way to convert a record type to mutable or read only without having to type it all again? Kind of like ReadOnly in TS, or the opposite way. module Person = { type t = {name: string, age:...
View Article