Live data from Hacker News

I tried Gleam for Advent of Code

blog.tymscar.com

71–80 of 223 posts

Re: I tried Gleam for Advent of Code

#72

I don’t know gleam, but surely list.map(fn(line) { line |> calculate_instruction }) Could be written list.map(calculate_instruction) ?

You're right, but loads of times I just left that there because I probably did something more involved in the map that I ended up deleting later without realising.

Re: I tried Gleam for Advent of Code

#73
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.

Ah right, I remember now.

> Guards are a bit limited in that they cannot contain function calls,

I feel like that's not a small sacrifice.

> but that's a problem of the BEAM and not something Gleam could control.

Could Gleam desugar to a case expression like I wrote above?

Re: I tried Gleam for Advent of Code

#74
post #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…

double space before each line for code formatting

Re: I tried Gleam for Advent of Code

#75
post #57

Earlier quoted context omitted.

> For those that don't know its also built upon OTP, the erlang vm This isn't correct. It can compile to run on the BEAM: that is the Erlang VM. OTP isn't the Erlang VM; rather, "OTP is set of Erlang libraries and design principles providing middle-ware to develop [concurrent/distributed/fault tolerant] systems." Gleam itself provides what I believe is a substantial subset of OTP support via a library: https://github…

Hi, I’m the creator of Gleam! The comment you are replying to is correct, and you are incorrect. All OTP APIs are usable as normal within Gleam, the language is designed with it in mind, and there’s an additional set of Gleam specific additions to OTP (which you have linked there). Gleam does not have access to only a subset of OTP, and it does not have its own distinct OTP inspired OTP. It uses the OTP framework.

(I know Erlang well, but haven't used Gleam)

The library the parent links to says this:

> Not all Erlang/OTP functionality is included in this library. Some is not possible to represent in a type safe way, so it is not included.

Does this mean in practice that you can use all parts of OTP, but you might lose type checking for the parts the library doesn't cover?

Re: I tried Gleam for Advent of Code

#76
post #70
post #68

Earlier quoted context omitted.

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.

There is though?

https://tour.gleam.run/flow-control/guards/

Re: I tried Gleam for Advent of Code

#77
post #74
post #69

Earlier quoted context omitted.

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…

double space before each line for code formatting

Thank you! TIL

Re: I tried Gleam for Advent of Code

#80

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?

Most Scheme implementations don't have generics, and you have to deal with a different map function for every data structure.

Gauche has a generic sequence interface which is great, and it's one of the reasons as a Python user I like Gauche as my "daily driver" Scheme.

Post reply on HN