Live data from Hacker News

Elm: a functional reactive programming language that compiles to JavaScript

elm-lang.org

21–30 of 51 posts

Re: Elm: a functional reactive programming language that compiles to JavaScript

#21

Hey, this is my project! :) I am surprised it got posted here, but I am also glad to see people are interested. One note on the title of this post: Elm compiles to HTML, CSS, and JS. Not just JS! I think this actually an extremely important distinction! It differentiates the project from templating libraries which still ultimately have you think and write in HTML. It also distinguishes it from scripting languages (li…

Very interesting project. I notice the site itself is written in Elm; it would be great if we could see the source code for the site, any chance of adding some of it to the examples section?

Thank you! And yes, that has been a really good way to test the language out. I don't want to add it to the examples because I use some internal-only functions to make it work nicely. It's also not terribly instructive. You can see it at (http://elm-lang.org/edit/Elm.elm) if you really want. Due to some implementation issues with Element sizing and some Element abstractions, there is some suboptimal stuff in there, but I am working on it. It should be shorter and prettier when the language and implementation gets more mature.

For instance, I am really unhappy with padding/margin, so that almost certainly come out. I have a nicer abstraction in mind that should solve HTML's problems with padding/margins/positioning. I can't say it will happen soon, but it's on the way.

P.S. If you want to look at other files, adding 'edit' to an Elm file gives you the source right now. http://elm-lang.org/edit/...

Re: Elm: a functional reactive programming language that compiles to JavaScript

#22
post #14

Why use Elm versus Flapjax? (Not a criticism -- sing your own praises!)

Flapjax still has you deal with the abstractions provided by HTML and CSS. I generally think these abstractions are pretty problematic, but more subtly, this means you must think imperatively (e.g. modifying the DOM) which doesn't really fit with the FRP paradigm. Flapjax is also based on the classical formulation of FRP which I think is not ideal for this setting (that is a big part of my thesis).

Nonetheless, I think Flapjax is a really cool project, and if you have to work with HTML, CSS, and JS directly, I can imagine it makes many things much more pleasant.

Re: Elm: a functional reactive programming language that compiles to JavaScript

#23
post #20

I really like this idea. I took a look at the Javascript output of the compiler, and noticed that effectively every statement of the program would result in a function nested within the function created by the last N statements. Since Javascript doesn't have tail call optimization, the browser will complain at some point when the stack overflows. Contrived, I know, but it looks like in Firefox 8 that happens at aroun…

This is an important issue! I'm aware of the problem and have some ideas of how to avoid it. My compiler is not actually doing any optimization at this stage, so this will be addressed when I give this more attention.

Re: Elm: a functional reactive programming language that compiles to JavaScript

#24
post #8

The original paper that introduced Functional Reactive Programming was the Fran paper: http://www.usenix.org/publications/library/proceedings/dsl97...

For those of you not familiar with FRP, it's a really great read! Hudak and Elliott really present their ideas clearly and elegantly.

Re: Elm: a functional reactive programming language that compiles to JavaScript

#25
post #14

Why use Elm versus Flapjax? (Not a criticism -- sing your own praises!)

Flapjax still has you deal with the abstractions provided by HTML and CSS. I generally think these abstractions are pretty problematic, but more subtly, this means you must think imperatively (e.g. modifying the DOM) which doesn't really fit with the FRP paradigm. Flapjax is also based on the classical formulation of FRP which I think is not ideal for this setting (that is a big part of my thesis). Nonetheless, I thi…

What specifically is your thesis? (I'm well-versed with the various formulations of FRP that have existed over the years.)

P.S. the navigation links at the top of the page don't work in Opera. Why aren't they just links + :hover CSS? (I presume they're written using Elm but that's not good if people for whom Elm doesn't work want to find out more.)

Re: Elm: a functional reactive programming language that compiles to JavaScript

#26
post #5

Something like this is badly needed to unify front-end web design and development.

Or even any front-end development, web or no. I'd love to write GUIs this way.

Clojure add-watch function looks like a way to get reactive programming like functionality.

http://lifeofaprogrammergeek.blogspot.com/2009/05/model-view...

Re: Elm: a functional reactive programming language that compiles to JavaScript

#27

It seems pretty neat, certainly a cool senior thesis! One suggestion if you take this further is to add a "dictionary" or "hash table" type. For practical programming problems, that is pretty necessary. But a really neat project - it's cool to see a functional programming take on the CoffeeScript-style compiling-to-javascript.

Thank you!

Dictionaries and Sets are high on the ever growing list of extremely important libraries :)

Also, it compiles to HTML, CSS, and JS. Not just JS!

Re: Elm: a functional reactive programming language that compiles to JavaScript

#28
I have a similar toolkit that uses pure javascript.

https://github.com/jordow/FaxJs

(see reactive example)

Functional reactive programming makes ui development so much easier. I've seen a lot of people starting to think this way about ui systems (with good reason). Good work!

I'd like to add similar compiled-in reactive optimizations to FaxJs as I'm sure Elm does. I commend you on choosing a static type inference system.

Re: Elm: a functional reactive programming language that compiles to JavaScript

#29

This surprised me: link has type (String -> String -> String), taking URL and label as arguments, and returning HTML code as a string (instead of as an Element). Then you need to use the text function (String -> Element) to make that link appear properly on the screen. This means that the text function (intentionally?) does not HTML-escape strings, even though examples suggest that it is the recommended way to put so…

This is my project. I agree that the type of link is a little weird. This was added pretty early on in the project and I haven't circled back around to rethink it. I'll try to address your questions: - Why is text necessary? Elements are all rectangles that have a uniform set of functions that can be applied to them. Strings are definitely not rectangles, and I think it is important that the type of String and Elemen…

"what it means to be a string includes styling (bold, italic, etc.)"

I would keep String and StyledString separate. Lifting to a StyledString is okay if you want to concatenate a String and a StyledString.

(plain "This is ") ++ (bold "GREAT!")

-> StyledString "This is GREAT!"

Strings are used for more than just rendering HTML, and I should be able to forget about styling in situations where styling is irrelevant.

"partial serialization of something..." ++ " another chunk"

-> "partial serialization of something... another chunk"

One immediate benefit of keeping String and StyledString separate, is that you won't forget which argument comes first in link.

link :: (String -> StyledString -> Element)

Re: Elm: a functional reactive programming language that compiles to JavaScript

#30
post #20

I really like this idea. I took a look at the Javascript output of the compiler, and noticed that effectively every statement of the program would result in a function nested within the function created by the last N statements. Since Javascript doesn't have tail call optimization, the browser will complain at some point when the stack overflows. Contrived, I know, but it looks like in Firefox 8 that happens at aroun…

Keep in mind that some implementations, notably V8, do do tail call optimization; and I'm sure IonMonkey or one of its successors eventually will.
Post reply on HN