
Thanks Daniel, that worked brilliantly.
I took yours and Brent's advice and brought play' and
getNewAnimal out of the where block. Also, the line "do ans <- ask $ show
question" was probably there due to some of the previous code, in which case
that line would have been slightly better (in my opinion, anyway), but I've
changed it now, because I prefer "do ans <- ask s" too.
Thanks again.
- Alex
On 8/14/08, Daniel Fischer
Am Donnerstag, 14. August 2008 22:12 schrieb Alex Watt:
Brent: getChar acts like getLine from what I can tell, it's a bit odd
Buffering indeed, in ghci, IIRC, stdin and stdout aren't buffered by default, for binaries the default is line buffering, so the char won't be gotten until you type a newline. Changing your code to
module Main where
import System.IO
main :: IO () main = do hSetBuffering stdin NoBuffering play (Animal "Dog") return ()
solves the problem:
Think of an animal, I will try to guess what it is... Are you thinking of a Dog? (y/n) n I give up, you win! Please help me improve my guesses! What is the name of the animal you were thinking of? Cat Now please enter a question that answers yes for a Cat and no for a Dog Does it meow?
Do you want to play again? (y/n) y
Think of an animal, I will try to guess what it is... Does it meow? (y/n) n Are you thinking of a Dog? (y/n) n I give up, you win! Please help me improve my guesses! What is the name of the animal you were thinking of? Cow Now please enter a question that answers yes for a Cow and no for a Dog Is it useful?
Do you want to play again? (y/n) y
Think of an animal, I will try to guess what it is... Does it meow? (y/n) n Is it useful? (y/n) y Are you thinking of a Cow? (y/n) y I win this time.
Do you want to play again? (y/n)
n Thanks for playing..
On the other count, I have to agree with Brent, the code is very nice overall, but play' and getNewAnimal as top level functions would be better, and I don't really like the line
play' question@(Question s y n) = do ans <- ask $ show question
I'd prefer do ans <- ask s
but that's purely a matter of taste.
HTH,
Daniel
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners