Hugs' behavior

Koen Claessen koen@cs.chalmers.se
Wed, 21 Feb 2001 17:15:04 +0100 (MET)


Hi,

I noticed an annoying incompatibility between Hugs (Feb
2000) and Hugs (Feb 2001), namely the fact that when
evaluating expressions of type `IO T' in Hugs (Feb 2001),
the following happens:

  1. when T = (), the IO action is just evaluated.

  2. when T /= (), the IO action is evaluated,
     *and* the result is printed, but only
     if T is an instance of Show.

  3. when T is no instance of Show, just a type error
     is generated.

Hugs (Feb 2000) has behavior 1. in all cases for T.

It is discussable which behavior is better. But I think
there should at least be a flag specifying what behavior you
want. And I also think that it should not be the default!

I don't like the new behavior because:

  * The Haskell 98 report does not say anything
    about printing the result of the main :: IO T action.

  * There is a rather arbitrary distinction between
    T = () and T /= ().

  * The error in case 3. is totally unacceptable.
    (Especially because there are interactive systems
    (such as Lava) which rely on Hugs' (Feb 2000) behavior.)

Take a look at the following examples, which illustrate some
of the issues.

  Prelude> return () :: IO ()

  Prelude> return id :: IO (Int -> Int)
  ERROR - Cannot find "show" function for IO result:
  *** Expression : return id
  *** Of type    : IO (Int -> Int)

This is really strange too:

  Prelude> return undefined :: IO ()

  Prelude> return undefined :: IO Int
  Program error: {undefined}

And here:

  Prelude> print "apa" >> return () :: IO ()
  apa

  Prelude> print "apa" >> return id :: IO (Int -> Int)
  ERROR - Cannot find "show" function for IO result:
  *** Expression : print "apa" >> return id
  *** Of type    : IO (Int -> Int)

What do you think?

/Koen.

--
Koen Claessen         http://www.cs.chalmers.se/~koen
phone:+46-31-772 5424      mailto:koen@cs.chalmers.se
-----------------------------------------------------
Chalmers University of Technology, Gothenburg, Sweden