Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Depended switching in netwire (Nathan H?sken)
2. Re: Depended switching in netwire (Ertugrul S?ylemez)
----------------------------------------------------------------------
Message: 1
Date: Fri, 09 Nov 2012 15:56:36 +0100
From: Nathan H?sken <[email protected]>
Subject: [Haskell-beginners] Depended switching in netwire
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hey,
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!") -->
start)
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?
Thanks!
Nathan
------------------------------
Message: 2
Date: Fri, 9 Nov 2012 18:15:22 +0100
From: Ertugrul S?ylemez <[email protected]>
Subject: Re: [Haskell-beginners] Depended switching in netwire
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Nathan H?sken <[email protected]> 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-0001.pgp>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 53, Issue 15
*****************************************