Dear,<br><br>Yesterday, while discussing with Cale and SamB on I suddenly came up with the crazy idea of scoped data declarations. After some brief discussion to check the validity, I finally came to the conclusion that they should be feasible. In addition, I don't think that they would require a high amount of changes in current compilers.
<br><br>Basically if you have something like:<br><br>module Main where<br>foo = let data Foo = Foo deriving Show in Foo\<br>main :: IO ()<br>main = print foo<br><br>One can see this as having an extra hidden module that defines Foo but that does not export it. The only change that is then required is that while compiling Foo, the hidden-ness of Foo must be removed.
<br><br>For instance, if one were to load this into, say, ghci (this is fictive of course):<br># ghci Main.hs<br>> :t foo<br>foo :: Codeloc2.Foo<br><br>There were initially some objections to this, because it is no longer feasible to actually write the type of the function foo. But if one looks at current GHC, this objection is already there:
<br><br>module A(foo) where<br>data Foo = Foo deriving Show<br>foo = Foo<br><br>module Main where<br>import A<br>main = print foo<br><br>As Excedrin then pointed out, importing this Main into ghci, gives<br>foo :: Foo.Foo
<br><br>And this notation can not be written in Main either, because Foo is hidden in A.<br><br>Therefore, I would like to note that scoped data declarations are just like hidden data-declarations with two extra requirements:
<br>1) Generate source-location-based submodule names<br>2) Add an extra import rule for those hidden modules in the subexpressions of where the data-declaration is being originally defined.<br><br>Comments are welcome, of course :)