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…
Grain: A strongly-typed functional programming language for the modern web
21–30 of 156 posts
Re: Grain: A strongly-typed functional programming language for the modern web
#22Re: Grain: A strongly-typed functional programming language for the modern web
#23Earlier 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…
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
#24Re: Grain: A strongly-typed functional programming language for the modern web
#25Re: Grain: A strongly-typed functional programming language for the modern web
#26How 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).
Re: Grain: A strongly-typed functional programming language for the modern web
#27Why not just compile OCaml to wasm? Why another language?
Re: Grain: A strongly-typed functional programming language for the modern web
#28The 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/