I have attached our module for the abstract data type Stack (we follow the Haskell 98 report and don't want to go into 1.4 compatibility). We expected the representation of stacks were hidden but Hugs let us write an expression with the "hidden" constructor StackC:
Stack> :l Stacks Reading file "Stacks.hs": Parsing.................... Dependency analysis........ Type checking.............. Compiling..................
Hugs session for: /opt/lib/hugs/lib/Prelude.hs Stacks.hs Stacks> StackC [1] StackC [1] Stacks>
This problem occurs only in the top level, if we program a client module importing the module Stacks and we try to write a expression using directly StackC then Hughs gives an error message (great!).
This is a bug in the top level, isn't it?
This is not a bug, it's a Feature[TM]! Notice the prompt says "Stacks>". This means that you are "in" the module Stacks, and so can see everything visible to a top-level function in the module Stacks. If you write another file, say Main.hs, containing just the single line "import Stacks", then do ":l Main", you will find Hugs session for: /usr/groups/haskell/lib/hugs/lib/Prelude.hs Stacks.hs Main.hs Type :? for help Main> StackC [1] ERROR: Undefined constructor function "StackC" Main> which I think is what you wanted. HTH. --KW 8-) -- Keith Wansbrough <kw217@cl.cam.ac.uk> http://www.cl.cam.ac.uk/users/kw217/ Cambridge University Computer Laboratory.