Earlier quoted context omitted.
Gleam has first class functions, so it has dynamic dispatch. Both of type classes and interfaces desugar to high order functions, so anything you write with them can be written with first class functions, though with a less concise API.
What you are saying is: no, it doesn't. Of course dynamic dispatch can be implemented in almost every language. The Linux kernel uses dynamic dispatch with C! But that's a hack, not a language feature.
I tried Gleam for Advent of Code
61–70 of 223 posts
Re: I tried Gleam for Advent of Code
#62It’s really good. But it needs generics. This is a huge downside. It’s a typed and clean functional programming language but it arbitrarily followed golangs early philosophy of no generics. Ironically golang is one of the most hated languages among many fp advocates. By the developers own action of adding generics ultimately the golang team admits they were wrong or that generics are better. If gleam gets popular I t…
Re: I tried Gleam for Advent of Code
#63It’s really good. But it needs generics. This is a huge downside. It’s a typed and clean functional programming language but it arbitrarily followed golangs early philosophy of no generics. Ironically golang is one of the most hated languages among many fp advocates. By the developers own action of adding generics ultimately the golang team admits they were wrong or that generics are better. If gleam gets popular I t…
Perhaps this is a silly question but how do you do functional with no generics? Arent they pretty much required for map/reduce/filter?
Re: I tried Gleam for Advent of Code
#64Gleam is really quite a nice language. I did AoC in it this year as well and came away with the following: (incomplete list for both positive and negative, these are mainly things that come to mind immediately) Positive: - It can be pretty performant if you do it right. For example, with some thought I got many days down to double digit microseconds. That said, you do need to be careful how you write it and many patt…
I did it in F# this year and this was my feeling as well. All of the List.map and Seq.filter would have just been better to be called off of the actual list or Seq. Not having the functions attached to the objects really hurts discoverability too.
Re: I tried Gleam for Advent of Code
#65I've looked at Gleam before but it didn't seem to have any mechanism for dynamic dispatch like interfaces or type classes. Did it change in the meantime?
The answer I’ve seen is “just pass structs of functions around”, which is just one step more explicit than the implicit version we’re all use to, but honestly I kinda like it to free ourselves of all the ceremony around generics.
Re: I tried Gleam for Advent of Code
#66Gleam is really quite a nice language. I did AoC in it this year as well and came away with the following: (incomplete list for both positive and negative, these are mainly things that come to mind immediately) Positive: - It can be pretty performant if you do it right. For example, with some thought I got many days down to double digit microseconds. That said, you do need to be careful how you write it and many patt…
case x ...
False ->
case x > 10 {
True -> ...
False ->
case x ...
False -> ...
}
}
}Re: I tried Gleam for Advent of Code
#67 list.map(fn(line) { line |> calculate_instruction })
Could be written list.map(calculate_instruction)
?Re: I tried Gleam for Advent of Code
#68Gleam is really quite a nice language. I did AoC in it this year as well and came away with the following: (incomplete list for both positive and negative, these are mainly things that come to mind immediately) Positive: - It can be pretty performant if you do it right. For example, with some thought I got many days down to double digit microseconds. That said, you do need to be careful how you write it and many patt…
I can live with these negatives. What irritates me the most is the lack of if/else or guards or some kind of dedicated case-distinction on booleans. Pattern matching is great but for booleans it can be kinda verbose. E.g. case x ... False -> case x > 10 { True -> ... False -> case x ... False -> ... } } }
case x {
n if x ...
n if x > 10 -> ...
n if x ...
}
Guards are a bit limited in that they cannot contain function calls, but that's a problem of the BEAM and not something Gleam could control.Re: I tried Gleam for Advent of Code
#69Gleam is really quite a nice language. I did AoC in it this year as well and came away with the following: (incomplete list for both positive and negative, these are mainly things that come to mind immediately) Positive: - It can be pretty performant if you do it right. For example, with some thought I got many days down to double digit microseconds. That said, you do need to be careful how you write it and many patt…
I do agree the language server is great. And it works in basically any IDE, which is another huge bonus.
With regards to having to type `list.map`, you actually don't need to! You can do this:
import gleam/list.{range, map}
import gleam/int
pub fn main() {
range(0,10) |> map(int.to_string) |> echo
}
Some libraries just aren't there, and I do wonder how hard it would be to port C libraries over. Something I want to play with!Re: I tried Gleam for Advent of Code
#70Earlier quoted context omitted.
I can live with these negatives. What irritates me the most is the lack of if/else or guards or some kind of dedicated case-distinction on booleans. Pattern matching is great but for booleans it can be kinda verbose. E.g. case x ... False -> case x > 10 { True -> ... False -> case x ... False -> ... } } }
There are (some) guards available though? You could rewrite your example as: case x { n if x ... n if x > 10 -> ... n if x ... } Guards are a bit limited in that they cannot contain function calls, but that's a problem of the BEAM and not something Gleam could control.
EDIT: I am wrong. Apparently there are, but it's a bit of a strange thing where they can only be used as clauses in `if` statements, and without doing any calculations.