Live data from Hacker News

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

grain-lang.org

131–140 of 156 posts

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

#131

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

It appears to allocate memory but never free it:

https://github.com/grain-lang/grain/blob/master/runtime/src/...

A lot of new languages start out this way, where they just assume memory is infinite and then eventually add the GC later. That's a really nasty ball of technical debt to be sitting on, and I've seen nascent language implementations die because they couldn't get past it.

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

#132
post #77

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…

It's generally better to highlight the existence of an error condition sooner rather than later. Compile time is better than runtime, evaluation time is better than via explicit value inspection. Non-signalling NaNs provide an easy way of distributing an invalid value widely throughout a program's data structures before it's discovered. The only reason to go the other way, and have silent NaN propagation, is if they'…

> exceptions, and consistent, universal use of monadic return types, are isomorphic and can have the same evaluation characteristics.

I feel like there is a small but important difference. Encoding exceptions in monadic return types allows the type system to guarantee that all exceptions are handled, or at least considered by the programmer. That is a very strong guarantee, especially as you put up layers and layers of foreign libraries and abstractions.

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

#133

Earlier quoted context omitted.

> Erlang for example follows that pattern (and has no concept of "exception"). Erlang absolutely has a concept of exceptions. They're even called exceptions: http://erlang.org/doc/reference_manual/errors.html#exception... .

Wow, I used Erlang extensively a few years ago and don't remember exceptions at all. (Exit reasons and process monitors, yes; but I don't think I ever wrote a "catch" expression, or encountered a library that expected me to do so.)

Yeah it's very rare to catch exception within processes, or to raise them explicitly. It's common to write something like

    {ok, Result} = foo()
though, and that raises badmatch if it fails, and you handle it in a supervisor.

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

#134

Earlier quoted context omitted.

> Erlang for example follows that pattern (and has no concept of "exception"). Erlang absolutely has a concept of exceptions. They're even called exceptions: http://erlang.org/doc/reference_manual/errors.html#exception... .

Wow, I used Erlang extensively a few years ago and don't remember exceptions at all. (Exit reasons and process monitors, yes; but I don't think I ever wrote a "catch" expression, or encountered a library that expected me to do so.)

You can use throw/catch to great effect when you need non local returns

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

#135

IMO modern web language should have some notion of events as in my Sciter ( https://sciter.com/event-handling/ ) for example: event click $(table > thead > tr > th) { // click on table header cell // 'this' is that th element } class Widget : Element { function attached() {...} event click $(span.up) { this.increment(); } event click $(span.down) { this.decrement(); } event mousedown { this.state.focus = true; } ...…

Can you explain how these differ from ordinary callback functions?

I haven't done any web development to speak of, but I've done a fair bit of GUI stuff, doing things like this snippet appears to in languages that don't have "events" as a separate category of thing.

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

#136
post #15

Earlier quoted context omitted.

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…

Well if you are worried about those 2 characters, you should be stoked about Grain, because it gives you type safety without ever defining types. Think how many characters you will save in an application by never defining a type and at no cost.

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.

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

#137

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…

> 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 discriminate between a missed lookup and a stored `undefined`. Though the latter must be discouraged, right?

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

#138
post #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?

I believe he person you're responding to means posting the public web page, not the submission here.

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

#139

Earlier quoted context omitted.

Well if you are worried about those 2 characters, you should be stoked about Grain, because it gives you type safety without ever defining types. Think how many characters you will save in an application by never defining a type and at no cost.

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.

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

#140
post #135

IMO modern web language should have some notion of events as in my Sciter ( https://sciter.com/event-handling/ ) for example: event click $(table > thead > tr > th) { // click on table header cell // 'this' is that th element } class Widget : Element { function attached() {...} event click $(span.up) { this.increment(); } event click $(span.down) { this.decrement(); } event mousedown { this.state.focus = true; } ...…

Can you explain how these differ from ordinary callback functions? I haven't done any web development to speak of, but I've done a fair bit of GUI stuff, doing things like this snippet appears to in languages that don't have "events" as a separate category of thing.

This

    observable.on("click", observerFunc);
    // or observable.addEventListener(...);
is an executable statement. And this

    class Widget : Element {

      event click { … observer's code … }
    }
is a declaration.

That executable statement needs to be called at some point of time. So the observable can be in two states - with and without that event handler.

While class declaration is an invariant (at least in Sciter) - as soon as element is in DOM it has that class and consistent set of event handlers in place. Such binding is done by, again, CSS declaration:

    widget {
      prototype: Widget url(path); //  controller
      display: block;   
      ...  
    }  
"I've done a fair bit of GUI stuff"

AFAIR VB6 and Delphi allow to declare event handlers without explicit/runtime binding - that's close as a concept to the above.

Post reply on HN