#What am I doing wrong with Gleam's new(ish) import syntax?

1 messages · Page 1 of 1 (latest)

edgy moss
#
// one.gleam
pub type Something {
  Something(Int)
}
// two.gleam
import one.{type Something}

pub fn get_something() -> Something {
  Something(1)
}

output:

❯ gleam run
  Compiling blocks
error: Unknown variable
  ┌─ /Users/benjamin/Projects/gleamtest/src/two.gleam:4:3
  │
4 │   Something(1)
  │   ^^^^^^^^^ Did you mean `get_something`?

The name `Something` is not in scope here.
#

seems like I can import the type or the variant, but i want to use both...

signal plank
#

You should be able to import both

#

import one.{type Something, Something}

edgy moss
#

well that does it

#

i thought about trying that but thought to myself, "no way lpil would let that work". apparently I know nothing!

azure wharf
#

its not "letting", its the exact design!

#

we changed it because previously a single Something import would import the constructor (if it existed) and simultaneously the type (if it existed) and we wanted it to be explicit which one you were choosing to import.

#

{type Thing} always imports the type, {Thing} always imports the constructor!

edgy moss
azure wharf
#

louis is working on a way revamped version at the moment 🙂

signal plank
#

It’s worth noting that this only looks weird when the constructor and type have the same name

#

And even then it’s easy to get used to

edgy moss
#

yep, all good now

#

I had seen code examples and the release announcement but apparently mostly glossed over them.

edgy moss
#

is this https://try-gleam.lpil.uk going to replace The Gleam Book above? or is there going to be a new Gleam book in addition to the interactive tour?