can this be written more easily?

Mike T. Machenry dskippy@ccs.neu.edu
Fri, 21 Feb 2003 00:21:24 -0500


Hey Everyone,

  I am having a hard time making a data structure that I can incrimentally
update. Mostly because dealing with arrays is so tough. Does anyone think
I'm going about this completely the wrong way? This is what I have.

data GameState = GameState {
  dTickets   :: Array Player (Array Ticket Int),
  fTickets   :: Array FugitiveTicket Int,
  history    :: [Move],
  dLocations :: Array Player Stop,
  fLocations :: Set Stop
}

removeTicket :: GameState -> Detective -> Ticket -> GameState
removeTicket s d t =
  s { tickets = (tickets s) // [(d,[(t,((tickets s)!d!t - 1))])] }

This remove ticket function is just terrible and it's common for me to have
to do operations like this. It's been hard to make this a function that I
can pattern match on, because which piece of data is manipulated depends on
the parmeter d (Detective)

Incase you all didn't notice, I decided to write a game in Haskell to learn
it. Thanks for all the useful help. I should know Haskell pretty well by the
end of all this.

-mike