
Nathan Hüsken
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.