[Haskell-beginners] IO Control Structures
Francesco Ariis
fa-ml at ariis.it
Tue Apr 23 15:32:58 UTC 2019
Hello Leonhard,
On Tue, Apr 23, 2019 at 02:55:22PM +0000, Leonhard Applis wrote:
> I don`t know how to do my main :: IO ()
> which should welcome the player, start the gameloop, and print godbyes the game if it's either won or lost
> Here i am missing a control structure, to demonstrate:
>
> show hello
> board = initialBoard
> while (not end board)
> board = gameLoop board
> show winner
>
> I could also make my Gameloop recursive, while i think that i get this working, it seems awfully complex (and ugly) to me.
Indeed making gameLoop recursive is the (a) solution.
As now `gameLoop` isn't much of a loop, is it?
If gameLoop has a signature like this:
gameLoop :: GameState -> -- Initial State
(IO Move) -> -- Input function
(State -> Move -> State) -> -- Logic function
(State -> IO ()) -> -- Blit function
(State -> Bool) -> -- "Should I quit?" function
IO ()
then main is trivial to write:
main = do
show hello
board = initialBoard
gameLoop board someInputFun makeMove drawState isOver
show ciao
More information about the Beginners
mailing list