gren-lang / gren-lang/compiler

Locally expose all from a module

Open
#224 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

language proposal
Dominant language
Haskell
Stars
503
Forks
29
PR merge metrics
No merged PRs in 30d

Description

This was a suggestion on the #220 language proposal, which I think deserves a proposal on its own.

Sometimes it can be quite handy to expose everything from a module, especially when the module defines a DSL like Html or Elm's elm-css package. However, exposing everything at top-level is, IMHO, rarely a good idea as you're now cluttering your namespace with all values from a given package, and potentially opening yourself to compile errors on package updates and the like.

I've long thought it would be nice to locally being able to expose everything. Locally meaning within a single function scope. I've had trouble coming up with a good syntax for it, though.

@joakin made aware that a feature like this exists in OCaml, and I think the syntax is quite alright.

This proposal suggest being able to locally expose everything in a module like this:

view : Html a
view =
  Html.( -- within these parens, every value in the Html module is available
    div []
      [ span [] [ text "Hello" ]
      , span [] [ text " you!" ]
      ]
  )

If the #219 proposal is to be implemented, it could also make it easier to locally decide how which functions an operator refers to:

floatExpr : Float.T
floatExpr = Float.( 42.0 + 59.0 * 2.0 )

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no implementation files, tests, or compiler entry points. Start by reading the related #220 and #219 proposals and the examples here, then identify where module exposure and function-scope syntax are parsed and resolved. Done means an agreed syntax and an implemented, tested local module-exposure feature.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.