Elm (Language)

Anyone looked at Elm yet?

Elm is a functional programming language for declaratively creating web browser based graphical user interfaces. Elm uses the Functional Reactive Programming style and purely functional graphical layout to build user interface without any destructive updates.

Comparison to JS: docs/from-javascript

Writing HTML apps is super easy with start-app. Not only does it render extremely fast, it also quietly guides you towards well-architected code.

###Features

  • No runtime exceptions
    Yes, you read that right, no runtime exceptions. Elm’s compiler is amazing at finding errors before they can impact your users. The only way to get Elm code to throw a runtime exception is by explicitly invoking crash.

  • Blazing fast rendering
    The elm-html library outperforms even React.js in TodoMVC benchmarks, and it is super simple to optimize your code by sprinkling in some lazy rendering.

  • Libraries with guarantees
    Semantic versioning is automatically enforced for all community libraries. Elm’s package manager detects any API changes, so breaking API changes never sneak into patches. You can upgrade with confidence.

  • Clean syntax
    No semicolons. No mandatory parentheses for function calls. Everything is an expression. For even more concise code there’s also destructuring assignment, pattern matching, automatic currying, and more.

  • Smooth JavaScript interop
    No need to reinvent the wheel when there’s a JavaScript library that already does what you need. Thanks to Elm’s simple ports system, your Elm code can communicate with JavaScript without sacrificing guarantees.

  • Time-traveling debugger
    What if you could pause time and replay all recent user inputs? What if you could make a code change and watch the results replay without a page refresh? Try it out and see for yourself!

What do you think?

1 Like

Looking at it now there seems to be a lot to like. Here’s the Syntax Guide. I also find the fact that it compiles interesting. You can define things after you call them as in their Markdown Example. It’s been a while since I’ve written in a language that compiles.

I don’t think I’d develop games with it. Their game examples are choppy or don’t work for me. (Ubuntu/Firefox)

But other than that I think it’s worth trying out! :slight_smile: Great find!

Oh and the elm-vim plugin has the integrated human readable error messages. :thumbsup:

1 Like

Elm is really neat. The time travel debugger is slick. Also, the functional reactive model just clicks in that language (whereas I’ve found it to be a weird fit in javascript). That said, it’s just for building web front ends (which is fine, if that’s all you do). And it’s really only FRP. I don’t have anything against FRP, but I’ve found the state you pass around balloons up pretty quickly. I’m interested to see how FRP evolves the next few years to support maintaining that.

1 Like

Here are some talks about it:

I was at strangeloop and saw this talk. http://www.infoq.com/presentations/elm-reactive-programming?utm_source=infoq&utm_medium=QCon_EarlyAccessVideos&utm_campaign=StrangeLoop2013

1 Like

Another great talk:

Elm vs React (ish!) (Elm wins! haha)

Good morning!

I started playing with Elm again over the long break. It’s been a while, so I was interested in what had changed.

I decided to do a rewrite of one of my current side projects; a small Rails app that is actually in production. This is not intended to be a strategic move. Just a learning exercise. Can I build this real world app using Elm.

I am also using couchdb as the backend. No other server.

All told, I’m learning a new database, a new front end language, and I’m wrestling with CORs. It could be a complete bust. I should learn some things though :smile:

Over the weekend, I finished the first component: I can login now.

Some thoughts on elm:

  • There’s a StartApp abstraction now. It generalizes Signal handling and drives you towards the “Elm Architecture”. It’s a welcome improvement.
  • elm-html is nice and easy to work with. Very similar to html libraries I’ve used in haskell and purescript. No magic syntax. Just elm. So much better then JSX.
  • elm-http is easy if you’re doing basic things. Because of CORS, I had to build my own requests though. They need refactored a bit. There doesn’t seem to be an elm-library for couchdb yet. Maybe that can be my contribution.
  • The time travel debugger was mostly a novelty for me. I may appreciate it more when I’m doing more complex things.

Working with elm was pleasant. I’m already comfortable in typed FP languages (Haskell, Purescript) and this was a similar experience. However, since elm focuses on appealing to people who aren’t comfortable in typed FP, it stridently avoids more complex types. There are no monads, per se. They use Maybe and Either (called Result, in elm) and other convenient types, but try to present things in a way that is explicit and easy to pick up.

Most helpful compiler I’ve ever used. Rather then fighting with errors, it felt more like a TDD session. I’d write some code, there’d be some useful errors, I’d fix those errors, repeat until it compiles and then BANG! Working component.

My plan for tonight it to start a navigation component and try to combine that with the login component I already have. I’m hoping this will help me better understand component nesting and how components can communicate. For example, the navigation will change based on whether the user is logged in.

As long as I don’t throw my hands up in frustration, I’ll report back with what I find.

2 Likes

Thanks @kofno - Elm seems like a logical for use with Elixir, which I plan to start learning properly next year.

Which learning resources did you use?

I look forward to seeing future updates and your app if/once you are ready to share it :003:

I just used the various elm docs. The elm-architecture tutorial is quite useful. GitHub - evancz/elm-architecture-tutorial: How to create modular Elm code that scales nicely with your app

The material is pretty approachable.

1 Like

Today’s elm wisdom (from hard earned experience):

Don’t try and do everything as a Signal or a Task. Most of your elm code will be functions taking arguments and returning values.

This may sound obvious. It did to me. But I definitely got sucked into trying to do all my app communication through the Signals and Effects pipeline.

There’s a strong emphasis in Elm tutorials on those techniques. They are distinct to Elm, and so highlighted. I found myself trying to copy those patterns everywhere. Most of the time, the real solution is just “return that from your function”.

Anyway, thought I’d share one of my face palm moments. Sometimes those are the best teachers.

2 Likes

Last night I implemented incoming and outgoing ports. Ports simplify interop with native Javascript. In this case, I used them to communicate with Stripe to accept credit card payments.

I’m starting to get comfortable with Elm. I’m hoping to have enough material to post a blog post over the holidays. Well… maybe right after the holidays.

2 Likes

I can’t wait to read it!

2 Likes

Same here - can’t wait to read it Ryan!

Also, when I signed up the domain for the Elixir forum I did the same for an Elm forum - I figured all three forums as part of a family would be beneficial as people would know what to expect at either of them (a friendly community!) as well as of course being visible to others in the network hopefully leading to more members/visitors. (The other two in particular should come up as the first result for anyone search for an Elm or Elixir forum - which in turn helps us here.)

Perhaps when I get around to figuring out how to do multiple Discourse installs on a single server how does @kofno feel about be a mod on the Elm forum and @Ohm on the Elixir forum? @danielpclark is a mod here and I think you make a good trio :003:

1 Like

I would consider it a great privilege to be a mod on the Elm forum. Thank you for the consideration!

Just let me know when you are ready! :smile:

1 Like

Awesome :023: Will keep you posted. It probably won’t be until the new year now tho - I desperately want to get this project out of the way so I can start learning both Elixir and Elm myself :003:

1 Like

I would be honored. :blush:

2 Likes

Great stuff :023: Will keep you guys posted :slight_smile:

I’ve been working on replacing a vanilla rails form with a form built in Elm. The goal is to try to reduce data entry errors by introducing a more interactive experience. The form itself isn’t complex, but it is part of the incoming sales funnel, so it has to work :). Today I finished the primary use case. I’m pretty excited about that.

That backend changes were minimal. I just added json support to the controller endpoints.

I can’t share this code, but once this is done, I’ll start a repo where I’ll publish some elm tutorials/blogs.

I’m hoping to fill in some of the documentation gaps that I had to overcome.

1 Like

Sounds good Ryan.

Have you thought about doing some videos? Perhaps like www.learnelixir.tv? I reckon that would be quite popular :023:

That’s an interesting thought. I did a few short videos a few months ago (about Pouch/Hood.ie/Knockout). They were mostly off the cuff. If I scripted them and had better audio equipment… well… it might not be too bad.

Here’s my three video experiment (I warn you again that it’s not very good…): null - YouTube

1 Like