If it's not too late to change, might I suggest doing away with the 'let rec ... and ...' syntax? The way to group mutually recursive bindings can be determined by finding the strongly connected components of the graph of the references between functions, so users don't need to manually specify it.
Grain: A strongly-typed functional programming language for the modern web
141–150 of 156 posts
Re: Grain: A strongly-typed functional programming language for the modern web
#142Dart anybody?
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.
Re: Grain: A strongly-typed functional programming language for the modern web
#143If it's not too late to change, might I suggest doing away with the 'let rec ... and ...' syntax? The way to group mutually recursive bindings can be determined by finding the strongly connected components of the graph of the references between functions, so users don't need to manually specify it.
But then how do you shadow previous bindings? let f x = if (x == 0) then 0 else (f x)
Re: Grain: A strongly-typed functional programming language for the modern web
#144Earlier quoted context omitted.
I think JavaScript simply got it quite wrong by trying to be way too clever. In theory it is fine to say that dividing by 0 is Infinity but what can you do with Infinity? In practice that causes the output of your program be either Infinity or NaN but the problem is that is usually never what you want. Then you want to know "Why do I get a NaN here?" and you will have to study all of your program and single step its…
> I think JavaScript simply got it quite wrong by trying to be way too clever. In theory it is fine to say that dividing by 0 is Infinity but ... This wasn't javascript's idea. They're just following the spec. https://en.wikipedia.org/wiki/IEEE_754#Exception_handling
Re: Grain: A strongly-typed functional programming language for the modern web
#145Earlier quoted context omitted.
This seems like such an obvious solution it makes me wonder why creators of Haskell did not think of it? Lists are a very basic type used all the time if you don't get that right lot of the value of the great type-system is lost I would think.
They did. The elm-style version is in the standard libraries as: listToMaybe :: [a] -> Maybe a ( http://hackage.haskell.org/package/base-4.11.1.0/docs/Data-M... )
Re: Grain: A strongly-typed functional programming language for the modern web
#146Earlier quoted context omitted.
> 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? Yes and no respectively. It's intentional in the sense that the original Javascript was not intended to fault (much) because it was for basic scripting, so if one small script blew up it should not bring down the entire page'…
Invalid JSON parsing as `null` would be an exciting API decision, haha. One thing I think I like about JS over Python is that empty containers are "truthy". This, combined with non-raising missed lookups, tends to be pretty ergonomic. For me, at least. Though it is messier -- in Python `key in d` is well entrenched as an idiom, and in JS `if(d.key)` misfires if the value is zero, and `if(d.key === undefined)` doesn't…
PHP's json_decode does that. And yes `null` is also returned as a PHP NULL.
> Though it is messier -- in Python `key in d` is well entrenched as an idiom, and in JS `if(d.key)` misfires if the value is zero
Or false, or null, or the empty string, or NaN.
FWIW `if (key in d)` also works in JS if d is a native object, though you need `d.has(key)` if d is an actual Map object instead.
Re: Grain: A strongly-typed functional programming language for the modern web
#147Earlier quoted context omitted.
Well, the languages I'm using are Ruby, Python, Elixir, JavaScript so I definitely like not to write types. Still, I don't know how types work in Grain. The documentation doesn't say anything about it or it's very well hidden.
Are you asking how they are implemented? You'll have to read the compiler code for that. But the documentation does tell you... "No runtime type errors, ever. Every bit of Grain you write is thoroughly sifted for type errors, with no need for any type annotations." So you never write them, but you get all the benefits as if you did.
But how's that possible in general? Example, JSON parsing of data from a HTTP request. This is pseudo code
# request.data is
# {"a":1, "b":2, "c":"a string"}
data = parse(request.data)
total = data["a"] + data["b"] # 3
total = total + data["c"] # ops!
The last line is either a compiler error (how? forbidding input is not an option) or a runtime error (Grain doesn't have that) or what?Re: Grain: A strongly-typed functional programming language for the modern web
#148The 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. 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…
As John Carmack said: "...if you have a large enough codebase, any class of error that is syntactically legal probably exists there."
Re: Grain: A strongly-typed functional programming language for the modern web
#149Earlier quoted context omitted.
> I think JavaScript simply got it quite wrong by trying to be way too clever. In theory it is fine to say that dividing by 0 is Infinity but ... This wasn't javascript's idea. They're just following the spec. https://en.wikipedia.org/wiki/IEEE_754#Exception_handling
This IEEE spec is about Exceptions like exception for division by zero. As far as I can tell dividing by zero in JavaScript does not cause an exception, does it?