Let's say I have a monad called Watchable, which represents a value that changes over time. For example maybe it comes from a watch on a distributed configuration system like Chubby, or from polling a remote server.
With a bind operation I can transform one type of watchable into another:
bindWatchable :: (a -> Watchable b) -> (Watchable a -> Watchable b)
I can also use that plus a traverse operation to make it possible to use a -> Watchable b to transform one watchable list into another:
bindWatchableElements :: (a -> Watchable b) -> (Watchable (List a) -> Watchable (List b))
But perhaps the a -> Watchable b transformation is expensive. For example maybe we're transforming a watchable list of remote endpoints into a watchable list of data they return when polled, so the transformation involves setting up an RPC channel. We wouldn't want to tear down every RPC channel and set up all new ones each time one element in the list changes. Instead it would be better to reuse the ones for the endpoints that didn't change.
More precisely, I'd like the following properties:
When the watchable list changes, the transformation is called for an element if and only if it's not equal to the element in the same position in the previous list (or that position didn't exist in the previous list).
The b objects are destroyed as soon as the watchable (and anybody downstream) doesn't refer to them anymore. So we shouldn't keep around an RPC channel to an endpoint that was previously in the list because e.g. our memoization process doesn't understand that the value is no longer needed. I'm not just looking for a cache here; I need deterministic eviction.
Is there an elegant way to express this in Haskell?
I tried to come up with a way of creating a arbitrarily deep nested type where each instance depends on the type of it's parent, but I couldn't come up with any solution.
I was thinking about something like a type T with two type variables, where the second is itself a T which first type variable depends on its parent.
data T a b = T (a -> b) (T (b -> c) (T (c -> d) ...))
I know that in theory every type variable should appear on the left and right side, and I don't know if this is even possible at all, but I guess that there is some way of making this work.
My experience with GHC extensions like GADTs and RankNTypes is very limited but as far as I know this would be a usecase for those?
Extension A and B are both in meetme R. Extension C chanspy A with param(qow). so:
A can hear B, B can hear A.
A can hear C, C can hear A.
B cannot hear C, C cannot hear B.
Is there any way to block B from hear A temporary. And when C hangup, B will be able to hear A again ?
Thanks in advance.
Yes,you can kick off B to other confernce, after that bring back.
Or use mute/volume change via meetmeadmin.
You can do both using AMI.
I know of the documentation for -XUndecidableInstances, but I thought I'd ask for an elaboration.
Suppose I have two multi-parameter typeclasses (allowed with -XMultiParamTypeClasses)
class Foo a b
class Goo a b
Now, suppose I have a parameterized data type
data Bar a b
which I want to make an instance of Foo when one of its parameters is part of an instance of Goo. I'm not sure the previous sentence uses exact terminology, so here's what I want to write:
instance (Goo c d) => Foo d (Bar a d)
I'm not allowed to without the UndecidableInstances extension. Am I correct in thinking this is because the instance doesn't refer to the c type?
Should I...
Just enable the extension? Can somebody elaborate on what kinds of trouble it can get me into?
Add another parameter to Foo, so that the last instance declaration becomes something like Foo c d (Bar a d)? A problem with this is that I might have other instances of Foo that never make any reference to any such "fourth type parameter" (i.e. there are instances of the form instance Foo A B in unrelated parts of my code), so these would break. I'd rather fix my instance, not my class.
Create a new class FooGoo with enough parameters? I would feel like I'm repeating myself in that case, but at least I wouldn't break unrelated classes.
Does anyone have any words of wisdom?
Am I correct in thinking this is because the instance doesn't refer to the c type?
Yes, your code does not adhere to (from here):
For each assertion in the context: No
type variable has more occurrences in
the assertion than in the head
In general, you should be safe unless you add other instances that would, together, form a loop. Things only get really hairy (and compiler-dependent) when it comes to OverlappingInstances, and rightout evil when you go IncoherentInstances.
Without knowing more about what you're trying to accomplish it's hard to give sound design advice, but the first thing to check is whether you really, really need to have c as a parameter to Goo. You might be able to do express what you want to accomplish like this:
class Goo d where
bar :: d c -> Int
baz :: Quux c => d c -> Int
I am trying to work out the expression for a probability distribution (related to bioinformatics), and am having trouble combining the information about a random variable from two different sources. Essentially, here is the scenario:
There are 3 discrete random variables X, A & B. X depends on A and B. A and B are related only through X, i.e. A and B are independent given X. Now, I have derived the expressions for:
P(X, A) and P(X, B). I need to calculate P(X, A, B) - this is not a straightforward application of the chain rule.
I can derive P(X | A) from the first expression since P(A) is available. B is never observed independently of A, P(B) is not readily available - at best I can approximate it by marginalizing over A, but the expression P(A, B) does not have a closed form so the integration is tricky.
Any thoughts on how P(X, A, B) can be derived, without discarding information? Many thanks in advance.
Amit
What you're dealing with here is an undirected acyclic graph. A is conditionally independent of B given X, but X depends (I assume directly) on A and B. I'm a little confused about the nature of your problem, i.e. what form your probability distributions are specified in, but you could look at belief propagation.
Ok, it has been a long time since I've done joint probabilities so take this with a big grain of salt but the first place I would start looking, given that A and B are orthogonal, is for an expression something like:
P(X, A, B) = P(X,A) + (P(X,B) * (1-P(X,A)));
Again, this is just to give you an idea to explore as it has been a very long time since I did this type of work!
Your question is very unclear in terms of what you observe and what are unknowns. It seems like the only fact that you state clearly is A and B are independent given X. That is,
Assumption: P(A,B|X)=P(A|X)P(B|X)
Hence: P(A,B,X)=P(A,B|X)P(X)=P(A|X)P(B|X)P(X)=P(A,X)P(X)=P(B,X)P(X)
Take your pick of factorizations.