[Haskell-beginners] Depended switching in netwire

Ertugrul Söylemez es at ertes.de
Fri Nov 9 18:15:22 CET 2012


Nathan Hüsken <nathan.huesken at posteo.de> wrote:

> So I am trying to use switchBy:
>
>   lostWire = startScreenWire "YouLost" --> inhibit mainGameWire'
>   wonWire  = startScreenWire "YouWon"  --> inhibit mainGameWire'
>   mainGameWire' = (unless gameWon --> inhibit [wonWire]) . (unless
> gameLost --> [lostWire]) mainGameWire
>
>   mainWire = switchBy id mainGameWire'
>
> This does NOT work because:
> a) WireP Input GmaeState is not a monoid.
> b) The exception type for the main Game wire is "WireP Input
> GameState"
>
> I guess a) is easily solveable ... but for b) ... do I really have to
> change the exception type for mainGameWire (and all the wires it uses
> ...)?
>
> What is the "proper" way of doing this type of switching/how should
> switchBy be used?

The proper way is to use a different inhibition monoid for the inner
wire, something like:

    data WinState = Won | Lost | None

    instance Monoid WinState where
        mempty = None
        mappend None x = x
        mappend x None = x
        mappend Won _  = Won
        mappend _ Won  = Won
        mappend _ _    = Lost

    game = switchBy start (start None)
        where
        start None = startScreen "Welcome to the game" --> mainGame
        start Won  = startScreen "You have won!" --> mainGame
        start Lost = startScreen "You have lost, sorry!" --> mainGame


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/20121109/5f2c7c86/attachment.pgp>


More information about the Beginners mailing list