Hacker News new | past | comments | ask | show | jobs | submit login
Grain 0.4 – Cereal (grain-lang.org)
64 points by pjmlp 4 months ago | hide | past | favorite | 50 comments



A big missing piece is the why. From what I can understand, it's garbage collected, it has ADTs, lists and arrays, it compiles to WASM, it has a "modern" syntax. What's the use case? Who's the target audiance? What are the tradeoffs comapred to JS, OCaml and Rust? I don't see any milestones or projets on Github. Is there a roadmap? What's the goal? A fullstack language?

I feel like I really want the "no marketing bullshit" version of that frontpage. "Grain is a new language that puts academic language features to work". Okay, but what "academic language features"? ADTs and pattern matching? Linear types? What's your pitch for developers that see new languages every 6 months, with usually more features than ADTs and a WASM backend?

I'll add that the answer to those can be "We made Grain because we wanted to, without a specific audiance in mind except ourselves" and that would be fine. I would just like some clarity on the goals and scope of Grain.


I agree that a programming language should have a strong rationale behind its design, especially if they expect people to use it and take it seriously.

That said, I think there's so much left unexplored in the PL design space that new languages are probably worth writing, if only to explore that space.

In this case, it seems like the main feature is that it's designed specifically around the WebAssembly runtime.

Skimming the docs, it also looks like it's meant to be a kind of cleaned-up OCaml. I guess that's not very different from Reason, Rescript, or even Fable.

A "why this and not those things" document would make me more inclined to spend my energy on it. Does it run faster on Wasm than other similar languages? Does it have some interesting developer UX related to the Wasm sandboxing features? Does it have a nice build toolchain?


> Skimming the docs, it also looks like it's meant to be a kind of cleaned-up OCaml. I guess that's not very different from Reason, Rescript, or even Fable.

It's implemented in Reason, so presumably the authors see some advantage to this over Reason. Personally I think more distance from the OCaml ecosystem is a competitive advantage relative to Reason et al. Yeah, there are advantages to being able to plug into an existing ecosystem, but the disadvantage is that in practice you have to understand the host language that you're plugging into.


Reason doesn't really exist anymore. "Native Reason" was just reskinned Ocaml, and the thing previously referred to as ReasonML continues life as ReScript.


Reason does actually still exists. Rescript is a modified ReasonML syntax + BuckleScript. ReasonML is between the two, a foot in the OCaml world, a foot in the JavaScript world.


It may claim to be that, but in practice it is not. Most of the Reason repos have barely been touched in months, while ReScript continues to have a lot of momentum. The reasonml forums [1] are down to 3 posts in the last month, vs 85 in the rescript forum [2]. I don't know what you mean by "still exists", but in practice you can consider ReasonML to be dead, replaced by ReScript.

[1] https://reasonml.chat/ [2] https://forum.rescript-lang.org/c/general/1


It may not look active from the outside, but I'm sure that the companies that used it still use it, while Rescript is still very young.

> ReScript continues to have a lot of momentum

Rescript has 4k weekly downloads on npm. Typescript has 22 millions. Coffeescript 1 million. Reason 1.5k. Elm 22k and it's not the official installer. PureScript 2.5k.


> It may not look active from the outside, but I'm sure that the companies that used it still use it, while Rescript is still very young.

I think I might not have been clear when I said that reason is dead. Let me try again: ReasonML was a sort of collaboration between bucklescript (the ocaml->js compiler) and the Reason syntax. They recently parted ways, with the bukclescript part being renamed to ReScript (as well as using their own syntax). That leaves not much to be under the name "Reason", which is basically just a syntax.

The companies that use it (such as mine) are moving to ReScript. Or, to put it more accurately, they have always been using ReScript just people referred to it as Reason at the time.

> > ReScript continues to have a lot of momentum

> Rescript has 4k weekly downloads on npm

I meant relative to Reason. (fyi: rescript used to be called bs-platform, and that continues to have 8k downloads, so it's more like 12k for rescript)


Totally agree, my criticism are only for the website, not for the language itself.


> What are the tradeoffs comapred to JS, OCaml and Rust?

JS: Static types

OCaml: Readable, familiar syntax, presumably none of the "many standard libraries" problems. Hopefully the community is significantly less toxic.

Rust: Garbage collected. Yeah, I know that the borrow checker gives you more than just memory management, but having to deal with the borrow checker really slows most people down a lot (even if they're experienced) and most applications can't trade that much developer velocity for an extra bit of safety and performance.

> What's your pitch for developers that see new languages every 6 months, with usually more features

Presumably "fewer features"?


That's a great overview, and I think Grain would benefit from a page like this. "X for Y programmers" is a useful pattern.

> OCaml: [...] Hopefully the community is significantly less toxic.

What do you mean by this?


OCaml's community has always struck me as really toxic and hostile to newbies. If a newbie asks a question however politely, they're frequently berated as though asking for help is cheating and everyone should learn things the hard way as they did. Alternatively, if the community doesn't have a good answer (e.g., "How do I do X in OCaml?"), they often respond with some variation of "You're stupid for trying to do X" or "If Jane Street can make millions without X, then your company doesn't need it either!".

Of course, every community has some toxic members, but in my experience they are so pervasive in the OCaml community that it virtually characterizes the entire community. And I've heard every justification including "Everyone is mean to the OCaml community, so the OCaml community is mean to everyone else".

Anyway, I don't care to get into an argument about whether or not OCaml's community is toxic, I'm happy to agree to disagree.


> Anyway, I don't care to get into an argument about whether or not OCaml's community is toxic, I'm happy to agree to disagree.

I'm not interested in arguing either, I was asking because I've been interested by OCaml for a long time and it's always nice to know in advance about broken stairs. Thanks for sharing.


That makes sense. My "I'm not interested in arguing" wasn't directed to you per se, but to any who might be interested in responding argumentatively.


And Americans often expect a ton of hand-holding. OCaml is a mature language with lots of relatively mature projects, tends to have a ton of documentation, etc...

Here's one of my favourite blog posts ever concerning open source and some expectations: https://www.catuhe.com/le-syndrome-du-puppy/


This is not an "Americans" thing. This is about the community of programmers in general growing at a very fast rate, and many people not having formal education, and formal education not always giving people the real world skills they need.

It's true that OCaml is a mature language, it's also quite stable considering its age. It has lots of relatively mature project, but it's also missing some pieces that people expect from the ecosystem of a language (the "recent" post about Darklang moving away from it because of a lack of Google Cloud libraries is an example of that).

"tends to have a ton of documentation" is wrong though. OCaml users are not blind to their own flaws, and often point out themselves that the documentation of most libraries is basically "look at the code".

About the blog post you posted, I think you're misinterpreting what people say. It's not about asking the OCaml community to put in even more work than they already did. They don't owe me anything. They don't owe a new user anything. That's a fact. However, when you're picking which language/ecosystem to invest time in, you're going to compare them. And when comparing them, you'll see that other ecosystems may have more libraries, libraries of higher quality, better documentation and/or more help for beginners. Just like the OCaml community don't owe us/me anything, I don't owe them anything and I'm free to chose whatever aligns the best with my interests.

What you interpret as "expecting a ton of hand-holding" is actually "being explicit as to why you choose something else than OCaml". You could then argue that OCaml users don't even want us and that saying this is useless. But that's not true. Here's an example of a subject in the official OCaml forum where they actively express their want for new users: https://discuss.ocaml.org/t/expanding-ocaml-appeal-to-future....


Hah, weird to make this nationalist. I studied at a top-tier French university without much hand-holding (and indeed tutored my French and English counterparts with their computer science lessons), but I guess I'm still not qualified to inquire of the OCaml community.

Thank you, however, for illustrating my point. :)


I've just heard every community described as 'toxic' and honestly 9/10 times I disagree.


> I've just heard every community described as 'toxic' and honestly 9/10 times I disagree.

That's pretty consistent with the "toxic community" hypothesis. I.e., people who are attracted to toxic communities think that others are too soft/welcoming, tolerate too much "hand holding", etc.


I don't participate in any communities except HN, but thanks for calling me toxic. Just an observation though. Reading docs, code examples and blogs is where I get info about languages.


I didn’t call you toxic, see https://news.ycombinator.com/item?id=28645997


This is a disgusting kafka trap you just tried to stuff another person in by implying the only reason anyone could disagree with you is if they're an abuser. You can take this slimy behavior elsewhere and it only shows that your remarks about the OCaml community are suspect.


It's not a Kafka trap. I'm responding to the specific rebuttal "OCaml can't be toxic because I don't find it toxic" by explaining that there are a couple of possibilities:

1. I'm wrong and OCaml's community is great OR

2. The parent doesn't find the OCaml community to be toxic because he's attracted to toxic communities

I specifically didn't say that the parent was toxic, although I think his comments (including his flagged nationalist comment) speak for themselves.

> You can take this slimy behavior elsewhere

You created an account just to accost me. ¯\_(ツ)_/¯


3. onus probandi?

I haven't interacted with the ocaml community enough to form any opinion, but honestly "the toxic community hypothesis", as you put it, is intellectual garbage.

With the same reasoning, one could argue that yours is a textbook example of the "overly sensible guy hypothesis", which states that only unreasonably sensible people would complain about communities rather than adapt.

It's pretty obvious that toxic communities do exist, and the "overly sensible guy hypothesis" is nonsensical, but your demeanor is implying that the user you were responding to is himself toxic, which I don't find at all reasonable.


I suspect you mean “sensitive” and not “sensible”? In any case, I’m not that sensitive. I went through the mill 15-20 years ago when programming communities were quite a lot more hostile toward newbies (certainly “welcoming” was not something communities concerned themselves with). But I do have the good sense to know that this isn’t constructive. And anyway, if you (or whomever) think OCaml’s level of toxicity is roughly the sweet spot, why do you care if I disagree? Perhaps you think I’m overly sensitive, but it’s not like I’m going to lose sleep over it. :)


I think an interesting advantage of Grain is that it not only compiles to wasm but is wasm-first.

Bringing existing languages to wasm is incredibly important, and probably that is 99% of wasm today. But a new wasm-first language that is designed specifically for wasm can do some things better.

For example, it is much easier to get tiny wasm files from a wasm-first language if it was designed for that.

Another example is wasm GC. The current proposal is making good progress but the type system will never be "perfect" for all languages (there will be extra casts, for example). A wasm-first language could (once wasm GC stabilizes) tailor itself to that for optimal results.


I honestly don't know enough about WASM to know how important being WASM-first is. That could be a nice thing to add to the website.

About the GC, that's true, but that also means that they may have to rethink significant parts of the language once the GC proposal is accepted.

Considering they talk about academic features, I could imagine something like linear types.


This website is nice, but here's something it could do with: a page describing what makes Grain different and amazing.

It's got a tutorial that goes through basics like types and functions. It's got a blog with release notes. But it could do with a sales pitch like Zig's overview doc.


Personally I clicked into the "getting started" page and the examples answered more of my questions, however indirectly. "Oh, this is an ML dialect with a readable syntax (and presumably none of the OCaml baggage)! It's a bit like Rust with a GC!"


Other than immutability by default and pattern matching I don’t see the Rust connection.

Out of curiosity, what is OCaml’s baggage that you’re thinking of?


> Other than immutability by default and pattern matching I don’t see the Rust connection.

They're both MLs with familiar syntaxes.

> Out of curiosity, what is OCaml’s baggage that you’re thinking of?

Dependencies on OCaml toolchain, standard libraries, and ecosystem (which seems like it should be a feature but in practice it just means you need to understand two languages, two toolchains, and the nuances of integrating them).


Basics section of their language guide: https://grain-lang.org/docs/guide/basics

Grain GitHub Repo: https://github.com/grain-lang/grain

Tiny example: https://github.com/grain-lang/grain-web-example

*NEAR example: https://github.com/grain-lang/near-simple-counter

*This is related to one of the new features in this 0.4 release announcement.


> Grain format provides an opinionated code formatter tool for Grain source code

I think this is a great idea; for the lang devs to provide such a thing.

After using black & isort in pythons, the option of automatic consistent formatting for shared code really cuts down on manual formatting work.


I strongly agree. It makes it much easier for a language to compete with incumbent languages if it already has basic developer tools like a test suite, a build system, etc. it also has the benefit of centralizing in standardizing the developer experience, compared to some languages where it's difficult for a beginner because there is no obvious correct way to do things.

I agree about formatting too, although every once in a while I do wish I could protect a specific section from automated formatting. Custom format and can be nice for things like mappings/tables, and certain deeply-nested JSON-like structures such as MongoDB queries.


Formatter author here - we do have the ability to protect specific sections with a // formatter-ignore comment before the section you want the formatter to leave as-is.


Hmm, the advantage of an "official" formatter, is that the language itself could maybe support formatting directives?


gofmt is another excellent example.


For the people like me who felt like the website was lacking in rationale, I found a presentation by one of the authors that goes into more detail: https://youtu.be/O8tyml3xBMM


The website isn't very descriptive, as others have pointed out - it's difficult to get basic information (and any details) about the language.

Moreover, it's not clear who this is for.

People wanting an expressive language with good tooling will be disappointed, as there's no REPL, macros, conditions, MOP (although to be fair that's because there appears to be no object system at all), or symbolic datatype.

Meanwhile, those wanting the maximum performance possible will be disappointed at the presence of garbage collection.

Is the idea that this provides a convenient middle-ground? That might make sense, but at least from my perspective it's far enough away from that point on the efficiency/expressiveness design curve that I might as well just pick either Rust or CL.


Past related threads:

Grain: A strongly-typed functional programming language for the modern web - https://news.ycombinator.com/item?id=26922857 - April 2021 (80 comments)

Grain: Functional Typed Language for the Web - https://news.ycombinator.com/item?id=23789383 - July 2020 (2 comments)

Grain: A strongly-typed functional programming language for the modern web - https://news.ycombinator.com/item?id=17645004 - July 2018 (153 comments)


This looks like F# but with a noisier syntax. Perhaps it will be more familiar feeling to JS devs?

Looks like a tidy language though, it's just unclear to me what it offers over more established alternatives.


I was thinking, "This is JavaScript with a mut modifier from Rust... and a tiny bit of OCaml thrown in for good measure"

F# is like a VERY nice OCaml in my view... so I'm biased.


When there are announcements like this, I really love it when they begin with just a few words to orient me on what the project is about.

"Grain, the programming language that combines the latest research innovations with the speed and portability of WebAssembly,is pleased to announce the release of v0.4 - Cereal."


Yes, assuming that anyone knows what this thing is seems a unbelievably optimistic.


It would be nice if they showed code on the front page. Lots of marketing words, no idea how it works, what the language looks like, etc...


Kinda feels like a JavaScript version of Elixir


,kk Pngofp is




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: