Speculative application

spec g f a evaluates f g while forcing a, if g == a then f g is returned, otherwise f a is evaluated and returned. Furthermore, if the argument has already been evaluated or are not running on the threaded runtime, we skip the f g computation entirely. If a good guess at the value of a is available, this is one way to induce parallelism in an otherwise sequential task. However, if the guess isn't available more cheaply than the actual answer, then this saves no work and if the guess is wrong, you risk evaluating the function twice. Under high load or in a runtime with access to a single capability, since 'f g' is computed via the spark queue, the speculation will be skipped and you will obtain the same answer as 'f $! a'.

Speculative application with transactional rollback

specSTM g f a evaluates fg = do g' <- g; f g', while forcing a, then if g' == a then fg is returned. Otherwise the side-effects of fg are rolled back and f a is evaluated. g is allowed to be a monadic action, so that we can kickstart the computation of a earlier. Under high load, or when we are not using the parallel runtime, the speculation is avoided, to enable this to more closely approximate the runtime profile of spec.

If the argument a is already evaluated, we don't bother to perform f g at all.

If a good guess at the value of a is available, this is one way to induce parallelism in an otherwise sequential task.

However, if the guess isn't available more cheaply than the actual answer then this saves no work, and if the guess is
wrong, you risk evaluating the function twice.