Importing type variants #3232
Replies: 2 comments 1 reply
-
Of course, immediately after I post this I figure it out. 🤦♂️ I import import types.{type DataSource, Url, File} |
Beta Was this translation helpful? Give feedback.
-
Adding a thought on this subject, re something I've noticed early on using Gleam. Importing a larger number of variants in this way can get unwieldy, especially having to update imports if the custom type is extended or reduced at a later point in development. Using @Dan-C-Reed's example above, it would be useful if all variants didn't need to be imported, but could be accessed via the type in place, e.g.: import types.{type DataSource}
...
True -> DataSource.Url
... This would help clarify the relationship between variants locally too. Using the qualified import syntax, i.e. accessing via the module name, is possible and reasonable if there's only one custom type per module, but with multiple types each with multiple variants also potentially confusing. |
Beta Was this translation helpful? Give feedback.
-
I have a file called
types.gleam
that contains the following:and I'd like to use it in another file, so I import the
DataSource
type like so:This throws an error that
Url
is not in scope despite importingDataSource
. I think I must also need to import theUrl
variant ofDataSource
, however, I'm not sure how. When the function and the type live in the same file everything is peachy.Can someone advise me how to import a variant of a type?
Beta Was this translation helpful? Give feedback.
All reactions