[Haskell-beginners] Trying to write netwire combiner similar to multicast
Ertugrul Söylemez
es at ertes.de
Tue Nov 6 02:44:00 CET 2012
Nathan Hüsken <nathan.huesken at posteo.de> wrote:
> > 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
> interface:
>
> 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 ... :).
The problem with such an interface is the inflexibility. Notice that
removing a subwire will change the numbering of all subsequent wires.
The interface I suggested follows this basic idea:
shrinking ::
(Monad m)
=> [(a' -> a, Wire e m a b)]
-> Wire e m a' b
The reasoning is that this way you disconnect the individual values from
the positions in the subwire list. This will also make writing the
combinator a bit simpler. If you will here is an interesting
alternative:
data Subwire e m a b =
forall a'. Subwire (a -> a') (Wire e m a' b)
shrinking :: (Monad m) => [Subwire e m a b] -> Wire e m a b
It doesn't buy you much except for some minor additional type safety,
the cleaner type signature and the opportunity to use a crazy type
system extension. =)
By the way, you can find this style all throughout the Netwire library.
See for example 'context' and 'require'. You may also find that the
various context combinators from Control.Wire.Trans.Combine could fit
your need, although they do not multicast.
Final note: I renamed your 'manager' combinator to 'shrinking' to save
you from future name clashes, because I have planned to write a more
general manager combinator.
Greets,
Ertugrul
--
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...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121106/374552f9/attachment.pgp>
More information about the Beginners
mailing list