Gleam: Unqualified imports

Created on 23 Sep 2019  路  8Comments  路  Source: gleam-lang/gleam

Enable the importing of module fields so that they can be used in an unqualified fashion.

Possible syntax:

import gleam/pair.{Pair}

fn main() -> Pair(Int, Int) {
  Pair(1, 2)
}
help wanted

All 8 comments

@lpil hello~just hope you could help me...
I've make some changes, and currently:

import gleam/pair -> pr

this grammer passes, but

import gleam/pair -> Pair

returns:

3 | import gleam/pair -> Pair
  |                      ^^^^ Unexpected token
  |

Expected one of r#"[a-z][0-9a-z_]*"#

Where can I fix this?

Hi @djKooks ! I think the syntax we're after is more like this:

import gleam/pair.{Pair, map_first}

The syntax with -> has already been implemented for functions so no need to worry about that :)

@lpil hello~have some question.
I'm checking grammer.lalrpop file, and it seems this is allowing as for renaming function name, such as:

import gleam/pair as gpair

In this case how do we should define when importing multiple module field, like:

import gleam/pair.{Pair, first} as ???

Please let me know if there is any misunderstaning.
Thanks.

I've not settled on what the exact syntax should be yet but this is my current thinking:

import gleam/pair.{Pair as PairConstructor, first as first_function} as list_module

@lpil hmm...then in this case, are these same?

  • list_module.Pair(X, Y)
  • PairConstructor(X, Y)

Yes, that's right.

@lpil oh, is it updated?

Yes, I finished this off yesterday, minus the aliasing using as

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lpil picture lpil  路  6Comments

michaeljones picture michaeljones  路  6Comments

lpil picture lpil  路  7Comments

lpil picture lpil  路  7Comments

lpil picture lpil  路  7Comments