Using AI as part of the buildchain

I keep checking in an out of the ReScript ecosystem. I love it, but there are things I’m missing - automated bindings and better error messages.

To keep ReScript even more relevant, can we incorporate AI for error messages? Could we have an LLM reading the documentation and then explaining why, in this particular context of my code, the error message is there? Could it provide an example of what I should be doing instead or how I can fix it? Can it fix it for me?

here’s a toy example:


FAILED: src/tasks/Task.cmj

  We've found a bug for you!

  13 │ let taskfn = async (db: Mongoose.Connection.t, _task: TaskModel.t) => {
  14 │   let now = Date.make()
  15 │   let foo = now + 1
  16 │ 
  17 │   let oneYearAgo = Date.fromFloat(

  This has type: Prelude.Date.t (defined as Js_date.t)
  Somewhere wanted: int

rescript: [131/150] src/tasks/Task.cmj

1. explain the error
2. provide patched code where the error has been fixed```


Certainly, let's provide an explanation from the perspective of the compiler:

**Error Explanation (as the Compiler):**
   In the code you provided, there is a type mismatch error. The line causing the error is:

   let foo = now + 1

The now variable is of type Prelude.Date.t (which is essentially Js_date.t), representing a date, while you are trying to add 1 to it. However, somewhere else in your code, it’s expected that foo should have a type of int.

ReScript is strict about type safety, and it’s flagging this as an issue because you’re trying to perform an operation (addition) that doesn’t make sense between a date and an integer.

Patched Code (as the Compiler):
To fix this error and ensure type compatibility, you need to explicitly convert the date to an int or adjust your logic to match the expected type. Here’s a corrected version of the code:

let taskfn = async (db: Mongoose.Connection.t, _task: TaskModel.t) => {
  let now = Date.make()
  let foo = Date.getTime(now) + 1 /* Now, foo is an int representing time in milliseconds */

  let oneYearAgo = Date.fromFloat(
  /* Rest of your code */

In this patched code, we use Date.getTime to convert the date now to an integer (representing milliseconds since epoch) and then add 1. This way, foo is now of type int, and the error is resolved, ensuring type compatibility throughout the code.

Using some clever prompt engineering, could we have automatically fixed errors or really good in-context explanations of errors? are there other build systems already attempting to do this which we could look at?


Yes, yes, yes, and yes.
Just lmk if you’d like to dig deeper.
Some of these things need to be built a bit over time, but it’s pretty clear how to build these things now.
One question is how to serve such features. Currently, if the user of these features has an openai key, then serving is easy.
It’s now possible to use reasonably performant models that run locally, though they would need adapting to learn ReScript-specific things. Again, it’s known how to do these things, but it needs to be done.