gleam-lang / package-interface

📦 Work with Gleam's package interfaces
Apache License 2.0
5 stars 0 forks source link

Feature request: const definitions for all builtin types #2

Open TanklesXL opened 4 months ago

TanklesXL commented 4 months ago

When using this package I find myself wanting to check that functions accept/return certain types.

It makes sense to define them myself for custom types, but it would be great to have gleams primitive types represented as constants in this lib!

lpil commented 4 months ago

Could you share a bit of the motivation here? I would have though pattern matching would be sufficient here

TanklesXL commented 4 months ago

in this case i'm trying to assert that a function has 1 parameter that is a String, i'd rather not have to dig into the implementation details to make my own version of the builtin-types every time i need to compare something with them.

the issue for me as a user of the package is that I have no way of knowing the expected shape of the gleam builtin types without already having seen the json and decoded it to know what they should look like

lpil commented 4 months ago

There's no implementation details here, this data structure is a public API, and checking the Hex documentation it does describe the shape of prelude types.

They could still be useful perhaps, though I'm not sure the use cases. Could you share what you code might look like with and without them?

One thing that seems like a limitation for me is that list and result can't be used in guards as they are functions.