Language Showcase: Gren
Hi everyone! This showcase is oriented around Gren, an Elm-inspired functional language, created by Robin Heggelund Hansen. He’s accepting sponsorship for his work, too.
How would you describe Gren to the average programmer?
Gren tries to take the most important ideas from pure functional programming languages and present them in an easy-to-learn language which can be used for pretty much anything.
If you've heard of Elm, Gren is quite similar (in fact, it started as a fork of Elm), but we intend to support back-end development starting with our next release in December 2022.
If you haven't heard of Elm, or pure functional programming in general, it's a way of writing code that has no side effects. Side effects are things like mutations, exceptions, HTTP calls, file IO etc. These things are necessary for any real-world programming, and pure functional programming doesn't remove them from your toolset. Instead, pure functional programming makes you focus on the actions leading up to, and which come after, a particular side effect. In other words, the code you write doesn't contain side effects, even though your application does.
Another common trait of pure functional programming languages is that they have a strict, but flexible, static type system. This type system lets you model exceptional situations as type errors, instead of runtime exceptions. So, NullPointerExceptions don't exist in Gren; they’re a type error instead. Not handling an HTTP timeout is not an exception, but a type error, etc.
Pure functional programming makes for easy-to-follow code execution and have fewer bugs. Gren intends to expose that to as many people and as many platforms as possible.
Which problems is Gren trying to solve?
Haskell demonstrated the benefits of pure functional programming, however many people find it hard to learn and understand. Elm showed that you can take the important concepts of Haskell and distill it into an easy-to-learn programming language. The problem is that Elm only targets the browser. In addition, Elm hasn't had a release in a few years, even though there are bugs to fix and rough edges to smooth out.
Gren intends to take all the benefits of Elm and make it available to more platforms, like web servers and command line applications.
At the same time, we intend to continue evolving the foundation that Elm has laid down for us, by improving the language and extending the number of available APIs.
What are some of the toughest challenges with building Gren?
Gren compiles to JavaScript, and most JavaScript APIs are not pure, meaning they cause side-effects when used. One of the most tricky aspects of developing Gren is exposing a pure interface over impure APIs which, at the same time, is pleasant to use and easy to understand.
What's next for Gren?
The focus right now is on supporting the NodeJS runtime, so that people can write command line applications and web back-ends. The basic functionality for this will be included in our 0.2.0 release (targeted for December 2022) and more APIs will be made available throughout 2023.
Where can people learn more?
Our website contains enough information to get started. We also have a community on Zulip and curious individuals are encouraged to join the discussion!
Program comparison: arithmetic
Prompt: Implement a program which takes in a single string from stdin containing a basic arithmetic expression, such as “1 + 2 - 5”, evaluate it, and print the result.