<p>Let us take the example, the input/output effect. Ordinarily, one presents this with two algebraic operations <code>print</code> and <code>read</code>. We can then imagine that things get "printed out" and "read in" from some sort of a communication channel. In fact, that's how I/O works in a typical operating system.</p>

<p>Except that in a typical operating system one can open lots of communication channels: open files, bind to internet sockets, etc. Whenever a new channel opens, something <em>new</em> gets <em>created dynamically</em> (i.e., while the program is running). An operating system typically just creates a new integer, the "file handle", but that's just a cheap version of what we really want: an identifier that is guaranteed to be unique and that cannot be guessed by any part of the program, unless it was already given to it. (Integers can be guessed.) Let us call such a thing an <em>instance</em>. (In cryptography it is often called a <a href="https://en.wikipedia.org/wiki/Cryptographic_nonce" rel="nofollow noreferrer">nonce</a>, but they cheat and think of it as an "unguessable integer". In programming languages we can make sure that instances are abstract tokens that really are unguessable.)</p>

<p>There are other examples where we need to create new instances. One is <em>state</em>, i.e., a memory location with operations <code>update</code> and <code>lookup</code>. Typical programs want to allocate any amount of memory locations, each of which is then an instance of the state effect. In general, instances allow us to create <em>local</em> effects, such as local exceptions and local references. In many applications it is essential to have such effects, for instance so that we can guarantee that only a certain part of the program is allowed to use a certain effect.</p>

<p>There is a tendency among the theoreticians to ignore effect instances because they complicate the theory. I feel that they should not be ignored because a programming language without dynamic creation of effects is next to useless. Who wants to write programs in which all memory allocations, files, and sockets, have to be specified ahead of time?</p>

CC BY-SA 3.0
2017-11-18T12:40:43.090Z
Thanks! So dynamic instances are key here. Surpising then that only Eff has them, they seem like such an important feature. I hope to start my Master thesis in a few months and I am looking to do something with algebraic effects. I think something to do with dynamic instances could be interesting.
Labbekak
CC BY-SA 3.0
2017-11-18T10:18:49.783Z
2017-11-18T10:18:49.783Z
Andrej Bauer
<p>What exactly are dynamic effects? What does it mean to dynamically create an effect?</p>

<p>In a language with algebraic effects and handlers (such as Eff or Koka) one could already do different operations based on runtime information, for example:
<code>
if x &gt; 10 then
  get ()
else
  put 10
</code>
In this case the actual operation done will only be known at runtime. But in the Frank paper (<a href="https://arxiv.org/abs/1611.09259" rel="nofollow noreferrer">"Do be do be do"</a>) they talk about dynamic effects in the sense of ML-style references. In what sense are references a dynamic effect that cannot be done in Eff (without resources) or Koka? Also why were resources removed again from Eff?</p>

CC BY-SA 3.0
2017-11-17T15:54:51.197Z
You will have to be a bit more specific. What sources did you look at that speak about "dynamic" and "generative" effects? This could mean several things. Generative with respect to the types of return values? Dynamic as in "created at runtime"?
Andrej Bauer
CC BY-SA 3.0
2017-11-17T19:05:01.380Z
I updated the question a bit, but I guess it's still not specific enough. I am just unclear what is meant in the Frank paper when they talk about Dynamic effects and I couldn't really find any other paper on it, except for the "Eff directly in OCaml" report.
Labbekak
CC BY-SA 3.0
2017-11-17T20:59:04.523Z
Ok, I think you're talking about resources. It's not clear to me what your question is? You are using the phrase "dynamic effects" which I find to be unclear. I will ask again: where did you get this phrase from? What paper specifically? Then I can have a look to see what you're talking about. If you invented the phrase, then you'll have to explain it. As far as I can tell, you're talking about Eff's instances (not resources). The example you put in your question looks like this question is not research-level.
Andrej Bauer
CC BY-SA 3.0
2017-11-17T21:41:18.727Z
I got the phrase "dynamic effects" from the ["Frank" paper](https://arxiv.org/abs/1611.09259) (Future work section) and from the ["Eff directly in OCaml"](http://kcsrk.info/papers/eff_ocaml_ml16.pdf) (Higher-order effects). I have to think some more before I can formulate a good question. I agree that it's likely not research-level so I will have to post it somewhere else. Sorry to waste your time.
Labbekak
CC BY-SA 3.0
2017-11-18T10:05:07.053Z
Ok, thank you, you're talking about instances in Eff terminology.
Andrej Bauer
<pl.programming-languages>
Algebraic effects and handlers, dynamic effects
Labbekak
# Algebraic effects and handlers, dynamic effects

(Asked by: username_0 on 2017-11-17)

What exactly are dynamic effects? What does it mean to dynamically create an effect?

In a language with algebraic effects and handlers (such as Eff or Koka) one could already do different operations based on runtime information, for example:
`if x > 10 then
get ()
else
put 10`
In this case the actual operation done will only be known at runtime. But in the Frank paper (["Do be do be do"](https://arxiv.org/abs/1611.09259)) they talk about dynamic effects in the sense of ML-style references. In what sense are references a dynamic effect that cannot be done in Eff (without resources) or Koka? Also why were resources removed again from Eff?

**Tags:** pl.programming-languages

> **Comments:**
> **username_1**: You will have to be a bit more specific. What sources did you look at that speak about "dynamic" and "generative" effects? This could mean several things. Generative with respect to the types of return values? Dynamic as in "created at runtime"?  
> **username_0**: I updated the question a bit, but I guess it's still not specific enough. I am just unclear what is meant in the Frank paper when they talk about Dynamic effects and I couldn't really find any other paper on it, except for the "Eff directly in OCaml" report.  
> **username_1**: Ok, I think you're talking about resources. It's not clear to me what your question is? You are using the phrase "dynamic effects" which I find to be unclear. I will ask again: where did you get this phrase from? What paper specifically? Then I can have a look to see what you're talking about. If you invented the phrase, then you'll have to explain it. As far as I can tell, you're talking about Eff's instances (not resources). The example you put in your question looks like this question is not research-level.  
> **username_0**: I got the phrase "dynamic effects" from the ["Frank" paper](https://arxiv.org/abs/1611.09259) (Future work section) and from the ["Eff directly in OCaml"](http://kcsrk.info/papers/eff_ocaml_ml16.pdf) (Higher-order effects). I have to think some more before I can formulate a good question. I agree that it's likely not research-level so I will have to post it somewhere else. Sorry to waste your time.  
> **username_1**: Ok, thank you, you're talking about instances in Eff terminology.  

---

## 1 answers

### Answer by username_1 on 2017-11-18. Score: 3 | Accepted answer

Let us take the example, the input/output effect. Ordinarily, one presents this with two algebraic operations `print` and `read`. We can then imagine that things get "printed out" and "read in" from some sort of a communication channel. In fact, that's how I/O works in a typical operating system.

Except that in a typical operating system one can open lots of communication channels: open files, bind to internet sockets, etc. Whenever a new channel opens, something *new* gets *created dynamically* (i.e., while the program is running). An operating system typically just creates a new integer, the "file handle", but that's just a cheap version of what we really want: an identifier that is guaranteed to be unique and that cannot be guessed by any part of the program, unless it was already given to it. (Integers can be guessed.) Let us call such a thing an *instance*. (In cryptography it is often called a [nonce](https://en.wikipedia.org/wiki/Cryptographic_nonce), but they cheat and think of it as an "unguessable integer". In programming languages we can make sure that instances are abstract tokens that really are unguessable.)

There are other examples where we need to create new instances. One is *state*, i.e., a memory location with operations `update` and `lookup`. Typical programs want to allocate any amount of memory locations, each of which is then an instance of the state effect. In general, instances allow us to create *local* effects, such as local exceptions and local references. In many applications it is essential to have such effects, for instance so that we can guarantee that only a certain part of the program is allowed to use a certain effect.

There is a tendency among the theoreticians to ignore effect instances because they complicate the theory. I feel that they should not be ignored because a programming language without dynamic creation of effects is next to useless. Who wants to write programs in which all memory allocations, files, and sockets, have to be specified ahead of time?

> **Comments:**
> **username_0**: Thanks! So dynamic instances are key here. Surpising then that only Eff has them, they seem like such an important feature. I hope to start my Master thesis in a few months and I am looking to do something with algebraic effects. I think something to do with dynamic instances could be interesting.  

---

