Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locally expose all from a module #224

Open
robinheghan opened this issue Sep 12, 2023 · 2 comments
Open

Locally expose all from a module #224

robinheghan opened this issue Sep 12, 2023 · 2 comments
Labels
language proposal proposal of a major feature to the language

Comments

@robinheghan
Copy link
Member

robinheghan commented Sep 12, 2023

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 )
@robinheghan robinheghan added language proposal proposal of a major feature to the language accepted The issue has been reviewed and accepted for implementation labels Sep 12, 2023
@robinheghan robinheghan removed the accepted The issue has been reviewed and accepted for implementation label Feb 8, 2024
@robinheghan
Copy link
Member Author

Removed the accepted label as I'm uncertain about the syntax.

@mbartlett21
Copy link
Contributor

Idea for syntax:

view : Html a
view =
  use
    Html, Html.Attributes
  in
    div []
      [ span [ class "first-word" ] [ text "Maybe" ]
      , span [] [ text " this would work?" ]
      ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language proposal proposal of a major feature to the language
Projects
None yet
Development

No branches or pull requests

2 participants