[Haskell-beginners] Trying to write netwire combiner similar to multicast
es at ertes.de
Mon Nov 5 17:29:49 CET 2012
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. You seem to be filtering out
produced results and trying to keep only the inhibition values, which of
course does not make much sense and triggers the type error you are
Also your interface seems very unsafe to me. I suggest the following
shrinking :: (Monad m) => [Wire e m a b] -> Wire e m a [b]
Then normally 'a' could be something like Map K A.
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 836 bytes
Desc: not available
More information about the Beginners