4 ms·
> unless you're passing a parameter that introduces an additional effect F into the function This definitely is overkill, I just wanted to illustrate that it w
by isaacimagine 5y ago
> unless you're passing a parameter that introduces an additional effect F into the function
This definitely is overkill, I just wanted to illustrate that it was possible. You're correct: usually, a generic effect indicates you're passing a closure to the function that may execute additional effects:
fn filter_users<F>(
cond: fn<F>(User) ->{F} Bool,
users: List<User>
) ->{F} List<User>
If filter_users calls the closure cond, effect F will be performed, so filter_users must perform F as well.
In the case where there are no external effects, F will be inferred to be the union of the empty set and whatever effects are used in the body of the function. Some languages are actually pretty strict about this, and explicitly declaring an empty effect set may mark the function as pure, which may not be what you want!