4 ms·
> The multisync macro was implemented to enable you to define both synchronous and asynchronous IO procedures without having to duplicate a lot of code. This i
by mastax 10y ago
> The multisync macro was implemented to enable you to define both synchronous and asynchronous IO procedures without having to duplicate a lot of code.
This is great! There are a lot of little things like this in the nim standard library that make life a lot easier. I should write more nim.
- lmm 10y agoThat shouldn't need a macro though. With higher-kinded types you can just write generic code that operates on futures or regular values.
- nnq 10y agoThat shouldn't need a higher-kinded type though. With macros you can just write generic code that operates on futures or regular values.
- lmm 10y agoCode that uses macros is no longer just code. You can't reason about them like normal code, nor use automated tools the way you usually would.
- virtualwhys 10y ago> that operates on futures or regular values. but what is the return type? The multisync example shows separate generated methods that return `string` and `Future[string]` depending on the method argument. If that's the case then blocking and non-blocking operations need to be treated separately since operations defined on a result of `Future[string]` are not the same as those available on `string`. HKTs not only allow for both method argument and return type to be polymorphic, but also allow one to define the same operations (like map, flatMap/bind, fold, etc.) on the wrapped type.
- dom96 10y agoGlad you like it! I wrote it while I was improving the httpclient module which otherwise would have a lot of duplication. Now it has an (almost) perfectly symmetrical API for both synchronous and asynchronous sockets :)