4 ms·
I might be a bit dense but I didn't quite get it and the examples didn't help me. For instance, the first example SayMessage. Is it supposed to be an effect? Wh
by aatd86 1y ago
I might be a bit dense but I didn't quite get it and the examples didn't help me.
For instance, the first example SayMessage.
Is it supposed to be an effect? Why? From the function signature it could well be a noop and we wouldn't know the difference.
Or is it arbitrarily decided?
Is this all about notations for side-effectful operations?
- anon-3988 1y agoif I have to guess, it's something like this function will call fopen, fwrite, etc somewhere downstream. of course I am hoping to get corrected on this.
- lblume 1y agoIt might, if the effect is handled using these functions. You could also handle the effect using another handler, doing something entirely different. It is up to the caller how to handle effects, or propagate them up.
- scalaisneat 1y agobecause it is declared as an effect - and implements a handle. Think of it more like an interface. It turns out that many common patterns - async, IO, yielding can all be expressed with a handle - and the effect can be represented in the signature. This allows the code to have which effect its ran in, at runtime - other commenters pointed out its very similar to dependency injection.
- aatd86 1y agoOk so we are basically defining a named function signature that represents a side effect shape. Then the implementation of these side effect is done elsewhere and assigned as the capability of a function, which is now deemed as impure by the compiler. You're right, it looks a bit like an interface.