Live data from Hacker News

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

grain-lang.org

21–30 of 156 posts

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

#21

Earlier quoted context omitted.

> No runtime exceptions, ever. This is something I wonder about JS: there are a lot of places that exceptions happen in (say) Python that just return `NaN` or `undefined` in javascript. Is it intentional? Is it a good idea? Examples: the multiplication operator essentially never throws. Out-of-bounds (or "not found") lookups don't throw. I suspect the logic is "only throw if you have the wrong type for that operation…

The JS way is a mistake, intentional or not. Here's a little thought experiment: Your program ends up with an "undefined" in some variable 'x'. How did that happen? In JS it can happen in any number of weird and wonderful ways, e.g. you called a function which did a 'v[i]' or it could have just fallen off the end because someone forgot to check a return path, or... In Python there's much less scope what the problem c…

But JS programs must execute in uncontrolled environments, e.g. browser engines from the past and future with random extensions installed. A bondage-and-discipline language may help developers find logic bugs, but will make the users' experiences worse.

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

#23
post #15
post #9

Earlier quoted context omitted.

Grain is quite different. Grain is more functional (no classes or context, tuples). Dart compiles to Javascript. Grain compiles to web assembly. Dart requires you to define types. Grain provides type safety and zero runtime errors without ever defining types manually.

The documentation about types says to look at the Readme of the compiler, which is very short and doesn't tell anything about types. Same thing for many other entries in the side menu. The examples don't have any type declaration. So, type inference and no reuse of the same variable with a different type, even when forcing mutation? Unfortunately the documentation is still too skinny. A note to language designers: I…

( ) are only optional if { } are mandatory, which is not true for some languages. e.g. in Haxe, one can write

    static function isEven(n)
        return if (n 
i.e. An if expression consists of other expressions that may or may not be a block expression ({ }).

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

#24
To have a JavaScript feel with type inference, which I assume they are aiming for given the syntax, I would like to see extensible records (structural typing), which remove the need to declare nominal record types. Purescript and Elm both have this feature.

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

#26
post #4

How does the example in Functions section show that function is first class citizen? It is merely calling a function within another function. I would expect the second function to take in first function as a parameter (which JavaScript already has).

I was hoping for currying, but was disappointed when all the functions were fully applied. It don’t really see either, how this tells anything about first-class functions :/

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

#27
post #25

Why not just compile OCaml to wasm? Why another language?

Poking around in the sources, it looks like this is the OCaml compiler, with the frontend apparently tweaked to accept the new syntax. But this is not mentioned anywhere that I can see. The "Copyright copyright 2017-2018 Philip Blair and Oscar Spencer." line in the README is highly misleading in this context, since most of the actual source files are marked with OCaml's copyright header.

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

#28

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 don't think web languages should have comparisons with JS on their homepage now that we have wasm.

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

#30
How does do handle memory management? If I'm not mistaken, in webassembly programs use a fixed buffer to access memory, which means you need some runtime support to manage that, or apply some kind of technique like this[1].

[1] http://home.pipeline.com/~hbaker1/CheneyMTA.html

Post reply on HN