[Haskell-beginners] Ruby Quiz Solution #15 - won't work after compilation

Alex Watt el.zingo at gmail.com
Thu Aug 14 18:47:50 EDT 2008


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 <daniel.is.fischer at web.de> wrote:
>
> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20080814/71c1ebe5/attachment.htm


More information about the Beginners mailing list