A simple example of using the Polysemy Haskell package to implement the Guess-A-Number game.
This example uses Input
, Output
, Reader
, State
and Error
.
Note: I have no affiliation with the author.
You will need Stack
- Clone the repo.
- Enter repo directory.
- Execute
stack run
polytest [master●●] % stack run
====== Result from pure program
"> "
"> I'm thinking of a number between 1 and 100. Guesses allowed: 5"
"> Enter guess #1:"
"> 50 is too high."
"> Enter guess #2:"
"> 75 is too high."
"> Enter guess #3:"
"> That's not a valid number. You just wasted a guess!"
"> Enter guess #4:"
"> That's not a valid number. You just wasted a guess!"
"> Enter guess #5:"
"> That's not a valid number. You just wasted a guess!"
"> You ran out of guesses. Game over! The number was 24."
"> "
"> Play again? (Y/n)"
"> Starting a new game!"
"> "
"> I'm thinking of a number between 1 and 100. Guesses allowed: 5"
"> Enter guess #1:"
"> 75 is too high."
"> Enter guess #2:"
Completed with error: Failed to read
====== Running IO program
>
> I'm thinking of a number between 1 and 100. Guesses allowed: 5
> Enter guess #1:
50
> 50 is too high.
> Enter guess #2:
25
> 25 is too high.
> Enter guess #3:
13
> 13 is too low.
> Enter guess #4:
20
> 20 is too low.
> Enter guess #5:
23
> 23 is too low.
> You ran out of guesses. Game over! The number was 24.
>
> Play again? (Y/n)
n
> Goodbye!
====== Result from IO program
Completion with result: [False]