unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.75k stars 269 forks source link

Watch expressions with the `IO` ability #4252

Open hejfelix opened 1 year ago

hejfelix commented 1 year ago

I propose a feature where you can watch an expression while handling the IO ability:

io> printLine ("Hello, World!")

it would basically work like a regular watch expression, but the results would not be cached, i.e., saving the file reruns the code even if the expression has not changed.

A use-case would be debugging an HTTP request, re-running the request while changing the headers, authorization, deserialization etc. until the request completes successfully.

ceedubs commented 1 year ago

I agree that this would be a nice feature.

More formally, I think that it should work for expressions that have the type '{Exception, IO} a for all a. This would probably mean that you would need io> do printLine ("Hello, World!"). Unison could conceivably parse all io> expressions as though there is an implicit do at the beginning, but I fear that would be a bit too magical and newcomers would be confused why they don't need to delay their IO expressions in io> but they do elsewhere (like for a main function that they pass to run).

ceedubs commented 1 year ago

A natural extension might be to have io.test> expressions to mirror test> expressions.

hejfelix commented 1 year ago

I agree that this would be a nice feature.

More formally, I think that it should work for expressions that have the type '{Exception, IO} a for all a. This would probably mean that you would need io> do printLine ("Hello, World!"). Unison could conceivably parse all io> expressions as though there is an implicit do at the beginning, but I fear that would be a bit too magical and newcomers would be confused why they don't need to delay their IO expressions in io> but they do elsewhere (like for a main function that they pass to run).

Absolutely agree that it should require the suspension for clarity.