fpclass / perpetual-haskelling-initiative

Main repository for the CS141 Perpetual Haskelling Initiative
MIT License
0 stars 0 forks source link

Add change turn function to Game.hs and corresponding functions #19

Closed ghost closed 4 years ago

ghost commented 4 years ago

I have created some of the functions for the game to work, though I have not done the start game or process moves.

I'm gonna be a bit busy so I'll get to those if I have time but anyone else is free to do them in the meantime

oscar-h64 commented 4 years ago

It would be very easy to change the server so it gives a tuple (Deck, Deck). It was a list because it made the code much easier, then things were moved around and now its just a matter of changing [d1,d] to (d1,d) in src/Purestone/Server/Util.hs

dixonary commented 4 years ago

Ideally code should be given a type which captures exactly the valid inputs, so that we never have to check that the input is of the "right shape". If it should only be run with two decks then the type should represent that! :)

There's a nice overview of this principle by Alexis King here: Parse, don't Validate

oscar-h64 commented 4 years ago

I think we should change setup game to take (Deck, Deck) rather than [Deck], then we don't have the possible error condition.

Personally I don't really like using the Handler monad here, since it kind of locks to function to use with servant, I think it would be better if it was just IO so it could be used in lots of contexts, but I can see why its there. We could check the length of the decks in the connect function in the server, then we could either ignore the unmatched patterns, or use error as we were before, or even just use an empty list for the hand. That's just my opinion though, it might be best to keep it as it is

mbg commented 4 years ago

You could use (MonadThrow m, MonadIO m) => m (Deck, Deck). I believe that both IO and Handler are instances of both.

oscar-h64 commented 4 years ago

You could use (MonadThrow m, MonadIO m) => m (Deck, Deck). I believe that both IO and Handler are instances of both.

Wouldn't it be (MonadThrow m, MonadIO m) => (Deck, Deck) -> m Board, or am I misunderstanding?

mbg commented 4 years ago

I was only showing the return type to illustrate the idea, so yeah the full type would be what you wrote.

FergalOK commented 4 years ago

The main reason for the function being throwable was because of the use of [Deck] instead of (Deck,Deck)