Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/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. IO Control Structures (Leonhard Applis)
2. Re: IO Control Structures (Francesco Ariis)
----------------------------------------------------------------------
Message: 1
Date: Tue, 23 Apr 2019 14:55:22 +0000
From: Leonhard Applis <[email protected]>
To: "[email protected]" <[email protected]>
Subject: [Haskell-beginners] IO Control Structures
Message-ID:
<DNoEAi6yxlYTO3tEHrpCzJ6lAdW6JfpqOnneaNwBX1Yt3zKDy5cDLa7qlT3LaEJ7nPI8ah7RG1merMY3P8547jjmMH-MPwEaaM1np6NMwmc=@protonmail.com>
Content-Type: text/plain; charset="utf-8"
Hey there,
I am writing a simple game and the only missing part is IO (Sadly, i need that
to play).
I've got most things pure, e.g. makeMove :: GameState -> Move -> GameState,
initialBoard:: GameState and lost :: GameState -> Bool work pure and as
intended.
I also got a function gameLoop :: GameState -> IO GameState which asks for
Input and applies it.
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.
Best regards
Leonhard
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20190423/0256a91e/attachment-0001.html>
------------------------------
Message: 2
Date: Tue, 23 Apr 2019 17:32:58 +0200
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] IO Control Structures
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
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
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 130, Issue 7
*****************************************