[Haskell-cafe] Netwire woes: creating a wire with mkGen_

Ertugrul Söylemez esz at posteo.de
Sat Dec 31 00:50:28 UTC 2016


> keyQ = filterE (== 'q') . keyEvent
> keyA = filterE (== 'a') . keyEvent
>
> testWire2 = hold . (keyQ &> keyA)

This is the problem.  You actually have the 'keyEvent' wire twice in
there, which means that both are trying to take from the 'MVar', which
in turn means that in any frame if keyQ gets nothing, it's very unlikely
that keyA will get something (because it runs pretty much directly after
keyQ), and whenever keyQ gets something, it will clear the MVar, so keyA
gets nothing again.  The real solution is not to have keyEvent twice in
there:

    proc _ -> do
        keys <- keyEvent -< ()
        qKeys <- filterE (== 'q') -< keys
        aKeys <- filterE (== 'a') -< keys
        hold -< mergeL qKeys aKeys

Perhaps you would like to try the new [wires] library, which has a much
cleaner distinction between frameworks and the actual FRP description,
so mistakes like this are far less likely.  It's a cleaner library than
Netwire in general. =)

[wires]: https://hackage.haskell.org/package/wires


Greets
ertes
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20161231/3c04cefd/attachment.sig>


More information about the Haskell-Cafe mailing list