> Observer patern using the standard FRP conventions? Are these situations
> inside the aims of FRP?
There are several flavours of FRP that approach reactivity from
different angles. I'd say Grapefruit is the one most relevant to the
Observer pattern, since it models complex systems as a network of
interconnected circuits, where circuits are effectful entities, and they
can communicate through both discrete and continuous signals. The other
system that might be relevant is Yampa, since you model entities as
stateful signal functions (but unlike in Grapefruit they cannot perform
side effects), and connect them however you want. Incidentally, both of
these approaches are arrow based.
In contrast, Reactive aims to describe the (output over the) whole
lifetime of an entity as a pure value. Dependencies between entities are
established simply by defining one as a function of the other, and
mutual dependencies are naturally allowed. I don't think there's any
meaningful way to connect the Observer pattern to that. In fact, the
basic OO design patterns are often meaningless in functional
programming, because it's a completely different world.
Gergely
--
http://www.fastmail.fm - Or how I learned to stop worrying and
love email again
_______________________________________________
Reactive mailing list
Reac...@haskell.org
http://www.haskell.org/mailman/listinfo/reactive
Le 9 juin 09 à 19:09, Álvaro García Pérez a écrit :
> This has similarities to the OO Observer pattern (in fact, you can
> implement it using the pattern) and is also supported in some new
> scripting languages as JavaFX.
One thing the observer pattern doesn't give you is any guarantee on
the order of updates: when the observed value changes it updates all
the observers in no specified order. However if a value observes more
than one value this may result in glitches (i.e. values you actually
don't want to see).
For example suppose your value dependencies are as follows :
a = b + c
b = c + 1
i.e. a observes b and c, and b observes c and initially we have :
c = 0
b = 1
a = 1
If c updates from 0 to 2 any of the following two sequences of updates
may be seen with the OO observer pattern :
c = 2; a = 3; b = 2; a = 4;
c = 2; b = 2; a = 4;
But usually you don't want to see the a = 3, it's a glitch. FRP
systems update the graph of dependencies in topological order (i.e.
they ensure before updating a value that each value it depends on has
been updated) and you are guaranteed you'll only see the second
sequence of updates.
FRP can be seen as a form of value observation in the sense that
changes in a value get eventually propagated to other values that
depend on it. But it is clearly not the same as the OO observer
pattern as usually understood/implemented because of this ordering
issue. FRP is more subtle and powerful in the management of the
value's dependency graph.
Best,
Daniel_______________________________________________
Gergely
--
http://www.fastmail.fm - One of many happy users:
http://www.fastmail.fm/docs/quotes.html
> I agree that there are some issues about the cyclic dependencies
> with the observer pattern,
Note it is not a problem about _cyclic_ dependencies, the dependencies
I have shown is a directed acyclic graph. Cyclic dependencies are yet
another issue you can solve for example with fixed points and
infinitesimal delays but it's a different problem.
> but I think that considering it a glitch or not is a matter of
> phylosophical discussion.
The semantics you really want is no glitches (= instantaneous
propagation times aka synchrony hypothesis). Because you want to think
about your values as being for all t : a(t) = b(t) + c(t) and you
can't do that if you allow the glitches to occur.
You do the same kind of reasoning in electronics when you introduce
latches and clocks.
> In Daniel's example you will end with the proper value in "a" (even
> if you have an inproper value for some negligible instants). You
> only may consider this a problem if your system has poles near those
> values, which can turn it into a diverging system, and if the
> updating period is big enough to trigger those diverging effects.
> For almost any non real-time-control system this is not alike to
> happen.
You may think it's marginal but it's not: you get into problems as
soon as your update functions may performs some kind of side effects
(e.g. write something to a file).
A friend of mine ran exactly into the problem I described with the
observer pattern in Cocoa, all the glitches triggered expensive and
unused graphical updates and were ruining the interactive experience
with the system. Eventually he had to side-step the observation
mechanism for certain parts of his system.
> And of course, you can implement your own Observer patern imposing
> some policies in the update ordering, which can help to avoid the
> glitches.
Yes, you'll end up implementing an frp system. You'll see this will be
quite different from an observer pattern implementation because you
need more contextual information about the observers to perform the
update of the dependents under a synchrony hypothesis.
Best,
Daniel
I'm trying to implement something like the Observer pattern in a functional setting. Some people told me that maybe I will find what I want in FRP. The Observer pattern enforces the propagation of changes [...]
Well, to be specific, joinE is broken, and looks hard to fix.
The Monoid instance for Event is also broken, but I think only when
all Events involved are finite.
Further, I was trying to fix it, but GHC is broken.
I'd also like to note that LegacyAdapters is broken. I've got a fix
for the broken bits, which happens to break everything else. Blocked
on another GHC bug, though.
..until further notice, just assume "broken".
--
Svein Ove Aas