Live data from Hacker News

I tried Gleam for Advent of Code

blog.tymscar.com

61–70 of 223 posts

Re: I tried Gleam for Advent of Code

#61
post #52

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 think you might mean “ad hoc polymorphism” rather than “dynamic dispatch”. Gleam, C, Erlang, etc have the latter, not so much the former.

Re: I tried Gleam for Advent of Code

#62

It’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…

Gleam has always had generics! There’s no Gleam version without them

Re: I tried Gleam for Advent of Code

#63

It’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?

Gleam does have generics.

Re: I tried Gleam for Advent of Code

#64
post #60

Gleam 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…

> Having to type `list.map` instead of `map` or `dict.Dict` instead `Dict` a hundred times does add up over the course of a few weeks, and does not really add a lot of extra readability.

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

#65
post #43

I'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.

It’s discouraged to pass around structs of functions to replicate type classes in Gleam. Instead the preference is to not type class style patterns in your projects, favouring a concrete style instead.

Re: I tried Gleam for Advent of Code

#66
post #60

Gleam 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 -> ...
            }
       }
   }

Re: I tried Gleam for Advent of Code

#68
post #66
post #60

Gleam 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 -> ... } } }

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.

Re: I tried Gleam for Advent of Code

#69
post #60

Gleam 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 was also pretty surprised about the performance. It's not C, but it's so much faster than I'd guessed.

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

#70
post #68
post #66

Earlier 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.

You most likely asked an AI for this. They always think there is an `if` keyword in case statements in Gleam. There isn't one, sadly.

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.

Post reply on HN