Problems reading .input from testsuite with Haskell

20 views
Skip to first unread message

Tobias Svensson

unread,
Feb 19, 2012, 7:09:21 PM2/19/12
to proglang-course-2012
I seem to be having problems reading input from testsuite programs
when doing the interpreter in Haskell. My stdLib looks like this:

----------------------------------------------------------------

printInt :: Value -> IO ()
printInt (VInt i) = putStrLn $ show i

printDouble :: Value -> IO ()
printDouble (VDbl d) = putStrLn $ show d

readInt :: IO Value
readInt = do
ln <- getLine
let i = read ln
return (VInt i)

readDouble :: IO Value
readDouble = do
ln <- getLine
let d = read ln
return (VDbl d)

----------------------------------------------------------------

The printX all work great, and readX all work great when I test them
manually. But for some reason when I run with the test suite, the
program gets stuck forever at certain tests. I have had problems with
core111, good05, good07 so far and cannot test beyond these for this
reason...

I have verified that the line the code gets stuck on is "ln <-
getLine" in both readInt and readDouble.

Is there a different / better way of parsing input that I should be
using?

Arnar Birgisson

unread,
Feb 20, 2012, 3:50:04 AM2/20/12
to proglang-c...@googlegroups.com
Hi!

Does adding

hSetBuffering stdin NoBuffering

to the top of your main function help?

cheers,
Arnar

Tobias Svensson

unread,
Feb 20, 2012, 7:17:18 AM2/20/12
to proglang-course-2012
Thanks,
unfortunely that doesn't solve the problem.

However, I just found that the testsuite works if you run it in GHCi
instead of compile it:

$ cd testsuite/
$ ghci progs-test-lab2.hs
Prelude Main> :run main ../


This is because compiled programs handle IO differently:
http://www.haskell.org/pipermail/beginners/2011-October/008856.html

I'm not sure exactly what the difference is that causes this to work
only in the interpreter though.

On Feb 20, 9:50 am, Arnar Birgisson <arna...@gmail.com> wrote:
> Hi!
>
> Does adding
>
> hSetBuffering stdin NoBuffering
>
> to the top of your main function help?
>
> cheers,
> Arnar
>

Tobias Svensson

unread,
Feb 20, 2012, 7:18:47 AM2/20/12
to proglang-course-2012
For more specific info, when I compile the testsuite, it gets stuck on
-any- test that has input defined in its .input file.

Grégoire Détrez

unread,
Feb 20, 2012, 7:29:42 AM2/20/12
to proglang-c...@googlegroups.com
How did you build the test suite ? In the latest package, there is a makefile with the proper command, does that help ? Otherwise, could you come in the lab session this afternoon ?
Reply all
Reply to author
Forward
0 new messages