[Haskell-cafe] Syntax extension - adding import support to let/where bindings

Elliot Cameron elliot.cameron at covenanteyes.com
Wed Aug 5 17:46:07 UTC 2015


My initial attempt seems to have failed:

+1 on the idea.

I wonder if full-blown “import” is overkill for the desired effect. Many languages simply allow you to de-qualify a namespace within a smaller scope. I’m thinking of C++ at the moment: { using namespace std; … }

I think this would be preferable because it would still require that a module declare its “import dependencies” in a known place. I’m imagining chaos from large source files with several dozen import dependencies, but only a few of them defined in the “normal” place. Not to mention this would solve some of the worries about tooling, etc.

That said, there is syntactical boon from re-using the “import” keyword. Yet I don’t think it’s a stretch to make inlined imports be constrained by the module’s imports. It’s a simple compiler error: “Foo cannot be imported inline because it is not imported by the module”.

With or without the constraint, this would be an excellent feature.

Elliot


From: Haskell-Cafe [mailto:haskell-cafe-bounces at haskell.org] On Behalf Of Oliver Charles
Sent: Wednesday, August 5, 2015 12:56 PM
To: Evan Laforge
Cc: Haskell Cafe
Subject: Re: [Haskell-cafe] Syntax extension - adding import support to let/where bindings


On Wed, Aug 5, 2015 at 5:43 PM Evan Laforge <qdunkan at gmail.com<mailto:qdunkan at gmail.com>> wrote:
> In practice I use a lot more than just two symbols. The point is the
> repeated qualification quickly introduces more noise and obscures the intent
> of the code.

Well, qualification is only necessary for the symbols that conflict,
right?  It seems to me that if you want an EDSL with a certain
prelude, you have to make sure the prelude symbols are all distinct.
If you want to compose two DSLs, then you could make a third prelude
that imports the other two, but renames colliding symbols.

At this point I am working for the compiler (and in this case doing a lot of work!), but it should be the other way round - this makes me sad.

Unless there are many collisions... in which case, maybe don't define
your EDSLs like that in the first place?

My EDSLs for HTML and CSS are meant to reflect those actual languages as closely as possible. If I start renaming things just to "fit in" with other symbols, then I've started adding burden on my users.

Also, let's not forget this proposal is useful for more than just EDSLs, so lets not get too caught up on that - for example, one might wish to import Data.Text.Lazy or Data.Text in different locations depending on what they are working with. There are many packages out there with conflicting symbols that have fairly "localised" use sites, but at a granularity of a top-level definition rather than a module.

Currently if you want to  figure out all imports you parse the top of
the file and can stop at the first definition.  But with this feature
you have to parse the whole file and thus understand all haskell
grammar, including all extensions in use.  I'd have to give up on my
fast deps chaser and switch to slow ghc -M... which is maybe the right
way anyway, I don't know.

Ok, to be fair, I wouldn't, because I could choose to not use that
feature, but in *theory* :)  And while "you don't have to use it" is
always brought up, it seems to me the more successful the feature is
the more likely you do have to use it.

It makes me sad if we can't progress the language on the grounds that people's attempts at parsing the source code themselves would break. If you want to know all the imports, then we should be providing this information through tools for people to consume.

On the other hand, lots of languages have a "local open" feature like
this.  I think many of them make you first import the module, and then
you can "open" it in a local scope.  This would address both my "parse
the whole file for imports" objection and the "what about instances",
because module importing would be unchanged.

Indeed, this could be a path forward. I'm not really familiar with any languages that do this, could you link to some examples of how this works in other languages?

ocharles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150805/7e8ae934/attachment.html>


More information about the Haskell-Cafe mailing list