[Haskell-cafe] Imports at bottom, why not?

Christopher Done chrisdone at gmail.com
Tue May 20 19:10:45 UTC 2014


On 20 May 2014 20:41, Jochen Keil <jochen.keil at gmail.com> wrote:
>
> > The first technical problem I see is that a compiler can't easily
> > generate a dependency graph without first parsing the whole module.
>
> Pardon my ignorance, but couldn't you just ignore every line that
> doesn't start with 'import'?
>

I see two problems:

1) Standard Haskell has semi-colons for declaration separation, not just
lines. So you could write

x = do { putStrLn "Quoth I; sup?"; print "X" }; import Data.List; y =
"oopie"

You would have to parse this (to some depth) to figure out where x starts
and the Data.List import begins.

2) With Template-Haskell enabled, you'd need to run the TH to ignore
quasi-quotes that just happen to contain "import X", and if imports could
appear anywhere, then TH would probably allow it, too, which would mean
you'd have to run the TH in a module to find out what else it imports.

With the restrictions imposed on imports being directly after module
headers right now, a compiler can trivially scan through everything before
even starting to parse (and quickly point out import cycles, or missing
modules).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140520/2bdf86d7/attachment.html>


More information about the Haskell-Cafe mailing list