Live data from Hacker News

Grain: A strongly-typed functional programming language for the modern web

grain-lang.org

51–60 of 156 posts

Re: Grain: A strongly-typed functional programming language for the modern web

#51
post #48
post #40

I have a distrust for languages that advertise themselves as "strongly-typed" or "bringing sanity to the front-end" - the former doesn't have a single clear definition and the latter - while not the case here - is questionable in it's own right.

Moreover, they don't really show anything to make their point — I can't see any type annotations on the frontpage.

> it's 2018 > type annotations

https://en.wikipedia.org/wiki/Type_inference

Re: Grain: A strongly-typed functional programming language for the modern web

#52

The main page doesn't do a great job of showing what's interesting about Grain vs. JavaScript. The only hint is this: "No runtime exceptions, ever. Every bit of Grain you write is thoroughly sifted for type errors, with no need for any type annotations." Maybe show some examples of errors Grain would catch that JavaScript wouldn't, like Elm does: http://elm-lang.org/

> No runtime exceptions, ever. I'm curious how they handle JSON parsing. For example in Scala/Play you define the class you want to parse to, and if the JSON passed in at runtime doesn't match the shape of that class then you get a runtime exception. Obviously it'd be nice if that didn't happen, but I can't think of any alternative that would make sense.

You should look into other more saner json libraries. It's unacceptable to have a runtime error. Nowadays I recommend circe.

Re: Grain: A strongly-typed functional programming language for the modern web

#53

I mean, this looks interesting, but why was this posted prematurely? Now I have to remember to look this up again in two months when they actually have a website that isn't 3% done. Basically all of the docs are in the "todo" stage. I always get a bit annoyed when people post their pages way too early.

What makes you think that the HN poster has any affiliation with the project, or vice versa?

Re: Grain: A strongly-typed functional programming language for the modern web

#54

Earlier quoted context omitted.

Like comparing to Rust compilation to WebAssembly for example?

Does Rust have any DOM integration?

Yes. For a while, you've been able to embed JavaScript wrappers using stdweb (https://github.com/koute/stdweb). There are pre-built libraries covering much of the DOM. But you may need to submit PRs if you get heavily into or something else with non-standard APIs.

The shiny new toy is wasm-bindgen (https://github.com/rustwasm/wasm-bindgen), which will soon allow the use of WebIDL (https://heycam.github.io/webidl/) to wrap the entire browser API, if I understand correctly.

In practice, it all seems to work pretty well. But for public-facing sites, you need to watch the number of dependencies you include and keep the *.wasm size down.

Re: Grain: A strongly-typed functional programming language for the modern web

#55
post #54

Earlier quoted context omitted.

Does Rust have any DOM integration?

Yes. For a while, you've been able to embed JavaScript wrappers using stdweb ( https://github.com/koute/stdweb ). There are pre-built libraries covering much of the DOM. But you may need to submit PRs if you get heavily into or something else with non-standard APIs. The shiny new toy is wasm-bindgen ( https://github.com/rustwasm/wasm-bindgen ), which will soon allow the use of WebIDL ( https://heycam.github.io/webidl…

There are vdom/components-based libraries based on that as well e.g. Yew seems popular.

Re: Grain: A strongly-typed functional programming language for the modern web

#56

The main page doesn't do a great job of showing what's interesting about Grain vs. JavaScript. The only hint is this: "No runtime exceptions, ever. Every bit of Grain you write is thoroughly sifted for type errors, with no need for any type annotations." Maybe show some examples of errors Grain would catch that JavaScript wouldn't, like Elm does: http://elm-lang.org/

I think the marketing page is not doing a great job. Grain is a language compiled to WebAssembly. So comparing it with either Javascript or Elm is pointless

> Grain is a language compiled to WebAssembly. So comparing it with either Javascript or Elm is pointless

This ability is a tool and nothing precludes a wasm target for Elm (in fact Evan specifically expressed interest in it: https://github.com/WebAssembly/gc/pull/1#discussion_r1115011...).

Either way, comparing Grain to JS or Elm is anything but pointless, at the end of the day it's competing with them.

Re: Grain: A strongly-typed functional programming language for the modern web

#57

The main page doesn't do a great job of showing what's interesting about Grain vs. JavaScript. The only hint is this: "No runtime exceptions, ever. Every bit of Grain you write is thoroughly sifted for type errors, with no need for any type annotations." Maybe show some examples of errors Grain would catch that JavaScript wouldn't, like Elm does: http://elm-lang.org/

> No runtime exceptions, ever. I'm curious how they handle JSON parsing. For example in Scala/Play you define the class you want to parse to, and if the JSON passed in at runtime doesn't match the shape of that class then you get a runtime exception. Obviously it'd be nice if that didn't happen, but I can't think of any alternative that would make sense.

> Obviously it'd be nice if that didn't happen, but I can't think of any alternative that would make sense.

Returning a sum of success + error, as e.g. Rust's Serde[0] or Elm's Json.Decode[1] do.

The developer gets the feedback that the operation has failed at runtime, but they also get the feedback that the operation can fail and they must handle it somehow at compile-time, even ignoring the issue is an explicit decision.

[0] https://docs.serde.rs/serde_json/de/fn.from_str.html

[1] http://package.elm-lang.org/packages/elm-lang/core/latest/Js...

Re: Grain: A strongly-typed functional programming language for the modern web

#58

What is meant by "zero runtime errors?" An example of a "runtime error" is the head of an empty list; how does Grain handle this?

Presumably the head function returns a value of type Optional/Maybe, that needs to be pattern matched against statically.

Re: Grain: A strongly-typed functional programming language for the modern web

#60
post #32

The main page doesn't do a great job of showing what's interesting about Grain vs. JavaScript. The only hint is this: "No runtime exceptions, ever. Every bit of Grain you write is thoroughly sifted for type errors, with no need for any type annotations." Maybe show some examples of errors Grain would catch that JavaScript wouldn't, like Elm does: http://elm-lang.org/

I wonder how they handle array out-of-bounds accesses...

Likely like Elm, where indexing into an array returns a Maybe. OOB return Nothing, while in-bound returns Just .

Or they don't support indexing at all.

Post reply on HN