gleam-lang / stdlib

🎁 Gleam's standard library
https://hexdocs.pm/gleam_stdlib/
Apache License 2.0
468 stars 168 forks source link

List/Dict inconsistency #539

Closed marcelhas closed 6 months ago

marcelhas commented 6 months ago

Hello, I just tried Gleam for the first time and I think it's great! :star:

Just one minor thing I encountered: Is there a reason why I have to prefix the Dict type like dict.Dict, but the List type can be used directly when importing their module respectively? I would have expected that they behave the same, considering they are both building blocks of the language.

Example

import gleam/dict
import gleam/list

pub fn main() {
  let _l: List(Int) = list.new()
  let _d: dict.Dict(Int, Int) = dict.new()
  // Does not work.
  let _d2: Dict(Int, Int) = dict.new()
}

Error

gleam run
  Compiling main
error: Unknown type
  ┌─ /home/.../main/src/main.gleam:8:12
  │
8 │   let _d2: Dict(Int, Int) = dict.new()
  │            ^^^^^^^^^^^^^^ Did you mean `List`?

The type `Dict` is not defined or imported in this module.

Versions

# manifest.toml
# This file was generated by Gleam
# You typically do not need to edit this file

packages = [
  { name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" },
  { name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
  { name = "simplifile", version = "1.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "EB9AA8E65E5C1E3E0FDCFC81BC363FD433CB122D7D062750FFDF24DE4AC40116" },
]

[requirements]
gleam_stdlib = { version = "~> 0.34 or ~> 1.0" }
gleeunit = { version = "~> 1.0" }
simplifile = { version = "~> 1.5"}
gleam --version
gleam 1.0.0

Cheers!

lpil commented 6 months ago

Hello! You can import the dict type constructor in an unqualified fashion if you like! The difference is that List is part of the language, while dict is defined in a library and not part of the language itself.