[Haskell-beginners] Help with getLine and getChar

Avery Robinson avery at averyrobinson.name
Fri Oct 28 01:20:48 CEST 2011


I'm writing a program that calculates the maximum height of a stomp rocket
(or any free falling object) given the starting height of the object and the
amount of time that it takes to hit the ground. Here's what I have written:
http://pastebin.com/KBJdPEJd

The behavior that I am expecting is something like this:

Starting height (ft): [user enters something here]
Total air time (seconds): [user enters something here]
Maximum height (ft): [the program's answer]
Another? (Y/N)

Then everything starts over if the user presses y, and execution stops if
the user presses n.

What actually happens:
1. The program waits for user input for both of the two fields before
anything else, then it prints the prompts along with the answer.
2. The user needs to press enter before the their response to "Another?
(Y/N)" is reacted to. I'd rather that the response is instant after just the
y or n key is pressed.

I don't really understand exactly how lazy evaluation works in the context
of IO, so any help will be much appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20111027/9a469efa/attachment.htm>


More information about the Beginners mailing list