Few words of introduction

We all love Elixir. It’s expressive, it’s extremely readable and - first and foremost - It runs on BEAM — an incredible virtual machine that turns concurrency into something as natural and expected as NullPointerExceptions in Java 7.

But as every language does, it also has its flaws. Some are inherent, some are just religious choices that had to be made one way or another; and as the user (or rather fan) base grows, so does the demand to express your own preferences. Changes like piping to the last argument instead of the first can be introduced with simple macros. Some people craving for more advanced ideologies create entire toolsets extending the language (like Railway Oriented Programming or Saša Jurić’s Exactor). Some others commit to entire frameworks that start to look like DSLs instead (Witchcraft).

But even smartest macro can’t solve everything without surpassing the biggest meta-programmer’s limitation: syntax. So that’s what we changed.

Arguably one of the loudest religion choices is typing. Private jokes like “Strong typing is for weak minds” and “If you shoot yourself in the foot, it’s easier to solve the problem by being careful not to aim the gun at your foot than it is to make guns that don’t point down” roam around the community. Whether types are hot or not, is out of this article’s scope.

I like strong types. And I like Elixir.

And that’s why Elchemy was made.

What does strong typing give us anyway?

Generally strong typing pays attention so you don’t have to.

You put a typo in function params?

Compiler will tell

Your arguments are in wrong order.

Compiler will tell

You wrongly treat a list of {:ok, value} tuples as if they were just value ’s.

Compiler will tell.

So whether your application works on complex nested structures, you like extra safety, or you just suffer from short attention span, static typing probably will serve you well.

Elchemy to the rescue!

With all of those values in mind, we came out with Elchemy:

Without further and unnecessary descriptions. Elchemy is entirely about turning this:

Into this:

Does it work? Check by yourself.

“But wait. I just typed a : String

a = 1 And it totally went through. Where is the entire type safety in that? You suck!”

Worry not. The type safety’s there. Just not in the browser, but living safely in the depths of the entire toolkit to integrate Elchemy with your existing Elixir project.

And to prove and learn the basics of it, below we’ll write a simple example program from scratch.