[Haskell-beginners] Trying to write netwire combiner similar to multicast
nathan.huesken at posteo.de
Mon Nov 5 18:05:24 CET 2012
On 11/05/2012 05:29 PM, Ertugrul Söylemez wrote:
> Nathan Hüsken <nathan.huesken at posteo.de> wrote:
>> I am trying to write a netwire combiner similar to multicast. The only
>> difference is that when one of the wires inihibts, I want to remove it
>> from the list.
>> So this is my attempt:
>> manager :: (Monad m) => [Wire e m a b] -> Wire e m [a] [b]
>> manager ws' = mkGen $ \dt xs' -> do
>> res <- mapM (\(w,x) -> stepWire w dt x) $ zip ws' xs'
>> let filt (Left a, b) = Just (a, b)
>> filt _ = Nothing
>> resx = mapMaybe filt res
>> return (Left $ (fmap fst) resx,manager (fmap snd resx))
> Notice that Left means inhibition (...).
I was sure right meant inhibition ... thanks!
> Also your interface seems very unsafe to me. I suggest the following
> interface instead:
> shrinking :: (Monad m) => [Wire e m a b] -> Wire e m a [b]
> Then normally 'a' could be something like Map K A.
That would mean, the individual wires have to know there own id?!?
Mmmh, I will try to keep this bookkeeping out of the wires with this
shrinking :: (Monad m) => [Wire e m a b] -> Wire e m (Map Int a) (Int,b)
shrinking will assign the ids to the wires and returns them with the
result. I will see where this gets me ... :).
More information about the Beginners