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

Francesco Ariis fa-ml at ariis.it
Fri Dec 30 23:17:37 UTC 2016


On Fri, Dec 30, 2016 at 05:16:21PM +0100, Ertugrul Söylemez wrote:
> could you show us the source code of your event wires?  I suspect that
> this is not a Netwire issue at all, but an issue of one of the event
> wires draining the MVar, so the other one never actually sees a full
> MVar.

Hello Ertes,
    the source code is attached to the original message [1]; I'll
paste here the relevant bits. This is the wire where the events are
generated:

> keyEvent :: Wire s () IO (MVar Char) (Event Char)
> keyEvent = mkGen_ f
>      where
>            f :: MVar Char -> IO (Either () (Event Char))
>            f r = tryTakeMVar r >>= \mmv ->
>                  case mmv of
>                    Nothing -> return $ Right NoEvent
>                    Just c  -> putStrLn ("pop: " ++ [c]) >>
>                               return (Right (Event c))

And these are the three wires which filter/merge `keyEvent`(s):

> keyA, keyQ :: Wire s () IO (MVar Char) (Event Char)
> keyQ = filterE (== 'q') . keyEvent
> keyA = filterE (== 'a') . keyEvent
> 
> testWire2 :: Wire s () IO (MVar Char) Char
> testWire2 = hold . (keyQ &> keyA)

`testWire2` is the function that is giving me headaches (works for Q
keypresses but not A ones).


[1] https://mail.haskell.org/pipermail/beginners/attachments/20161227/c0585a78/attachment.hs


More information about the Haskell-Cafe mailing list