[reactive] instance Monad Behavior where ...

Thomas Davie tom.davie at gmail.com
Mon Nov 24 17:03:31 EST 2008

While hacking a bit on Creighton Hogg's Tetris game, I came across  
something interesting re composability.  I have made each tile appear  
as a taurus, and decided it might be fun if the tauruses span while  
you played (just for added vomit-worthyness).  So I set about changing  
my tile from a Geometry3 to a Behavior Geometry3.  This went well,  
until it came to getting the spinning tiles to display something based  
on the game state.  The tetris game is a Behavior GameState, where the  
game state stores the positions of the tiles on the board etc.

What I *want* is that I compute the current game state, by looking  
into the Behavior GameState, get a GameState up, and then apply a  
function createTetrisGeometry :: GameState -> Behavior Geometry3.   
This sounds a lot like (>>=) to me, unfortunately there's no Monad  
instance for Behavior though :(.

I've heard from various sources that the Monad instance is problematic  
for a couple of reasons.  I'd love it if we could have a bit of a  
discussion about why it's problematic, and if it can be fixed.



p.s. It is possible to hack round this problem by making a function  
createTetrisGeometry :: TimeT -> GameState -> Behavior Geometry3, and  
then using (uncurry createTetrisGeometry) <$> (time <^(,)^> tetris).   
The result currently looks something like this... http://www.cs.kent.ac.uk/people/rpg/tatd2/tetris.png

More information about the Reactive mailing list