The Effect Spectrum (I)
Effects of Intuition
In the march of pure functional programming toward pervasive mainstream use the notion of effects have become an interesting topic. I’ve begun looking at what you might call “the effect spectrum” or “the effect zoo”: the different kinds of effects and what they do (to your program).
I shall name these functions by personal preference, these names are likely unconventional but they have “symbolic” value.The first examples will not be effects at all but I will gradually move into effects over the next few posts, well maybe just one more post. I have a few ideas queued up on time-slicing, “forced” pre-emption (OS terminology abuse alert) and exceptions.
The structural notation will be a “pseudo/semi-formalism”, Haskell-like.
Exhibit 1: Non [ineffective]
This function takes no arguments, computes nothing, does nothing and returns no result. It is the computational equivalent of brain death.
structure
() → ()
substance
public void non()
{
}
Exhibit 2: Som [ineffective]
This function takes one argument and returns that argument. The “zero” function may be seen as a special case of the “one” function, accepting only the empty tuple.
structure
a → a
substance
public void som<T> (T x)
{
return x;
}
Exhibit 3: Som-Non [ineffective]
This function takes one argument and returns nothing as a result, never caring about what the argument actually was, you might call this a comatose function: it gets everything you say but can’t respond back with anything (the empty tuple () being the equivalent of silence).
structure
a → ()
substance
public void somnon<T> (T x)
{
}
Exhibit 4: Non-Som [ineffective]
This function takes nothing and returns something. It is the dual of comatose – it can only give and it always gives the same thing.
structure
() → a
substance
public T nonsom<T>()
{
return default(T);
}
Exhibit 5: Som-Time [time-"in"-effective]
This function takes something and returns that same thing, after some time. You might say it’s the functional equivalent of bullet-time; it slows down time (if e.g. we define time as state-transitions; ticks, or whatever). This means it has an effect, meaning its “effective” but this time-effect also makes it “in-effective”.
structure
a → Δ a
substance
public T somtime<T>(T x)
{
Thread.Sleep(1000);
return x;
}
One may argue whether this function actually contains a [side-]effect (messing with time) or not. In a sense all functions mess with time, as in the real world they take time to compute. So the result is some delta into the future where the argument is some point in the past, depending on when you look at it.
