[Haskell-cafe] A question about causality in FRP
apfelmus at quantentunnel.de
Fri Oct 14 15:05:21 CEST 2011
David Barbour wrote:
> Alan Jeffrey wrote:
>> A function (f : Beh A -> Beh B) is causal whenever it respects =t, i.e.
>> (forall t . a =t b => f a =t f b).
> Yes. Function outputs only depend on the past values of the input function.
> Your solutions for double and weird are accurate. Double is lifting the
> future at each instant into the present, which is obviously not causal. And
> the `weird` function presumes you already have a obtained a complete view of
> a behavior at each instant.
> The `problem` such as it exists: you will be unable to causally construct
> the argument to the `weird` function, except by modeling a nested/simulated
> world (i.e. modeling one FRP system within another). This is not an
> unrealistic endeavor, e.g. one might model the future position of a thrown
> baseball in order to predict it. In this sense, `weird` is not weird.
I concur with that. The function
double :: Behavior a -> Behavior (Behavior a)
double x = const x
is not causal because it makes all future values of the behavior x
available "at once". However,
weird :: Behavior (Behavior a) -> Behavior a
weird = join . fmap (. (+1))
where join a t = a t t
is clearly causal as a composition of two causal functions. The point is
that the innermost behavior was already available "in full", so it's
perfectly possible to evaluate it at any time desired.
Of course, the function
double' x t = \t' -> if t' <= t then x t' else _|_
More information about the Haskell-Cafe