[Haskell-beginners] Depended switching in netwire

Nathan Hüsken nathan.huesken at posteo.de
Fri Nov 9 15:56:36 CET 2012


I have main wire for a game:

  mainGameWire :: WireP Input GameState

and a wire for an info screen (to display a message):

  infoScreenWire :: Sting -> WireP Input GameState

I functions to test if a game has been won or lost:

  gameWon  :: GameState -> Bool
  gameLost :: GameState -> Bool

Now I want to switch between the info screen and the main game. A
different message should be displayed depending on if the player one or
lost. One working way is this:

  mainWire = F.fix (\start ->
               infoScreenWire "Press Enter to start" -->
               (unless gameWon . ((unless gameLost . mainGameWire) -->
(infoScreenWire "You LOST!") --> start)) --> (infoScreenWire "You WON!") -->

This works, but is pretty clumsy.

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?


More information about the Beginners mailing list