Hi,

Today, when I was restructuring my program, I discovered something nasty 
in one of Hugs' error messages. Simplified, it looked as follows:

  ERROR "Main.hs" (line 6): Type error in application
  *** expression     : useFoo mkFoo
  *** term           : mkFoo
  *** type           : Foo
  *** does not match : Foo

????? I was puzzled!

Later, it appeared I had made a mistake in renaming my modules, because my
system had looked as follows:

  module Baz( mkFoo ) where

    data Foo = Foo

    mkFoo :: Foo
    mkFoo = Foo

  module Bar( useFoo ) where

    data Foo = Foo

    useFoo :: Foo -> Int
    useFoo Foo = 3

  module Main where

    import Baz
    import Bar

    main = useFoo mkFoo

I had wished Hugs' error message to be something like:

  ERROR "Main.hs" (line 6): Type error in application
  *** expression     : useFoo mkFoo
  *** term           : mkFoo
  *** type           : Baz.Foo
  *** does not match : Bar.Foo

This brings us to another issue: what does it really mean when you export
a function from a module, but not the name of one of the types used in the
function type of that function?

Maybe we should not allow programmers to export a function whose type is
not completely known outside that module as well. If I had been forced
to write:

  module Baz( mkFoo, Foo ) where
    ...

  module Bar( useFoo, Foo ) where
    ...

Hugs would have told me:

  ERROR "Main.hs": Entity "Foo" imported from module "Baz" already defined
  in module "Bar"

which makes clear what the problem is.

Regards,
Koen.

--
Koen Claessen,
[EMAIL PROTECTED],
http://www.cs.chalmers.se/~koen,
Chalmers University of Technology.

Reply via email to