dynamic & dynamic/decode vs unqualified types that I don't really understand. #4989
Replies: 3 comments 3 replies
-
|
I found https://tour.gleam.run/functions/generic-functions which might be something although if I'm reading this properly, once a function with generic type params are used, that type is crystallized and it can't be treated as a different type? |
Beta Was this translation helpful? Give feedback.
-
|
You are correct there. Those are generic types. |
Beta Was this translation helpful? Give feedback.
-
|
Yup that's right, they're type parameters for a generic function. If you have not yet read the Gleam language tour def work through that. You'll have a much easier time once it has taught you all the features of the language. The The dynamic type is typically not used for FFI. Instead one typically exposes Erlang or JS APIs that have types consistent with Gleam's type system, and then those functions are imported into Gleam as external functions. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
hi!
this is a continuation of #4987
frankly, I think I'm a little bit confused about unqualified types in a mostly empty file with definitions like these:
https://github.com/Michael-Mark-Edu/bravo/blob/9ec7565fea973dac1192c266cd21c17cfeac256f/src/bravo/internal/bindings.gleam#L12-L18
where are
k/vcoming from? are there any pointers to docs with regards to this kinda thing?I'm not sure what this means when working with external functions like
ets:lookupthat return literally arbitrary data (#1717), some ets libraries touch on this, under "Why should I use Bravo over other libraries such as Carpenter?": https://hexdocs.pm/bravo/frankly, I don't understand how bravo's type system is working here: https://github.com/Michael-Mark-Edu/bravo/blob/main/src/bravo/internal/master.gleam
where is
kandvcoming from??? I'm obviously a lil bit confused about gleam's type system. at leastosetusesk/von the object definitionfor building a generalizable ETS library, what types should I be using on the ffi?:
bravo uses the same un-qualified
k&vtypes. I'm very confused: https://github.com/Michael-Mark-Edu/bravo/blob/9ec7565fea973dac1192c266cd21c17cfeac256f/src/bravo/internal/bindings.gleam#L20gts does something similar: https://github.com/zunda-arrow/gts/blob/main/src/ets/internal/ets_bindings.gleam
I've seen some amounts of
anytypeoranythingthrown around, I assume these were special escape-hatch keywords but maybe they are just the same kinda unqualified type that results in any kind of type being returned. how do that interact with the type system?my question is basically: can I somehow shoehorn
Dynamiconto all of this (like I have above) such that I can get typechecked erlang ffi interop (check that things are lists, strings, records, etc) when converting between a "black box" that is the erlang ets, but also have an escape hatch with dynamic for when I want arbitrary much-harder-to-qualify erlang data. like functions? gleam-lang/erlang#80 was created for atoms a long time ago, but is a patch to the stdlib required for every strict erlang type I want to be able to encode/decode? or maybe I have to optionally write some erlang code, with some type checks and create my equivalent:perhaps even narrowing down the accepted & returned types for my specific context.
sorry for the ramble! Still learning quite a lot about the language and learning is a windy process
Beta Was this translation helpful? Give feedback.
All reactions