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

Alex Watt el.zingo at gmail.com
Thu Aug 14 10:33:26 EDT 2008


If I call "main" in ghci, my program runs as it should, but if I try
compiling it, and then running the result of that compilation, i.e.:

$ ghc -o animal_game game.hs
$ ./animal_game

unexpected things occur, particularly "getChar" does not work correctly, and
if I take a route that doesn't lead to getChar needing to be called, the
program stops running at the end of 2nd run despite your response to the
do-you-want-to-play-again-question.

$ ./animal_game
....
Do you want to play again? (y/n)
y
....
Do you want to play again? (y/n)
y
Thanks for playing!
$

The source code is here: http://rafb.net/p/7fYlEV72.html
I don't know how long that will stay up there, so let me know if it's gone
and I'll repaste or find a better alternative.

What would also be nice is any comments on the actual code; as a begginner,
it's nice to get some feedback, and I might as well also ask the following
question. Originally I wanted to the types to be as such:

data Animal = Animal String
data Question a b = Question String a b -- where a is a Question or an
Animal, as is b

The problem is I wanted methods that had types that were able to accept
an argument of type Animal or Question, and for it to act appropriately on
that type, I tried adding them to common type classes (a new one I created
called 'Askable' which contained a method 'ask'), but I ran into a whole
bunch of problems. Is there any easy way to do it?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20080814/59b5b8a4/attachment-0001.htm


More information about the Beginners mailing list