My Favourite Gleam Feature
erikarow.land
erikarow.land
After mucking around with import paths in so many languages for so long, I like that elixir is like “all the namespaces everywhere”
One thing I've never thought about, but you could potentially just make a single file with all the imports and that would make it easier to check, but it still just feels too much like magic and loss of control.
I’d assume elixir looks at every file in the lib directory and compiles them. They all then get loaded into the beam vm with their respective module names
But that isn't how I was using the term “magic”, I was using it as a generic descriptor similar to how the Zig language refers to things that are done in the background, or hidden, without control from the user. I prefer knowing everything a file requires, that way I never double up, or have too many deps without my knowledge of everything that is in a system.
We wrestled with the same issue in PRQL. There we have "data last" in order to allow for currying and our pipe operator just pipes to the last argument so you still have the same pipeline syntax.
I also like the qualified imports. The lack of those was what turned me off Nim.
Rye has an interesting approach with the * syntax to allow injecting into the second argument for op-words: https://ryelang.org/meet_rye/specifics/opwords/
For anyone that hasn’t tried writing Elixir style code with the pipeline operator should definitely check it out. It’s fun to iterate in the repl too, since you can build it sequentially without adding braces for nesting calls.
It just doesn’t have static types, it has strong types.
That difference gives you the flexibility to avoid circumstances where static typing can be a hindrance.
For the rest of it, you have a conversation where the benefits of full static typing don’t exist in a distributed environment. Example, you’re making function calls to other nodes in the cluster and the node is updated while your code is running potentially changing the function call. You won’t get the chance to do a contract exchange live with other nodes, recompile and examine results.
Instead, you have to pattern match on the parts you care about just like with an API call to a server you don’t control.
Even with Gleam, static typing only protects your node. In a distributed environment you can’t validate everything and on the BEAM everything is a distributed environment.
Once you accept this, you realize that the benefit of static typing simply doesn’t exist here.
https://elixir-lang.org/blog/2024/06/12/elixir-v1-17-0-relea...
R.map(arr, (x) => x + 1)
and as part of a pipe in a data-last way: R.pipe(
[0, 1, 2, 3, 4, 5, 6],
R.map((x) => x + 1),
R.filter((x) => x % 2 === 0),
R.take(1)
)
I've really enjoyed using it and would recommend it to anyone who would like to write their typescript in a more functional way.Having the arguments order flipped means that currying and pipeline do not play nicely together.
I don’t see how the Gleam approach is better.