Write Elixir code using statically-typed Elm-like syntax (compatible with Elm tooling)
Clone or download
wende 0.8.0 / 2018-09-22
================
Latest commit 2f4aca0 Sep 22, 2018
Permalink
Failed to load latest commit information.
docs 0.8.0 / 2018-09-22 Sep 22, 2018
elchemy-core @ 918d15c 0.8.0 / 2018-09-22 Sep 22, 2018
elchemy_ex Closes #272 nested case fix (#273) Jan 31, 2018
example hotjar test Aug 19, 2017
lib/mix Closes #276 macro plugins (#331) May 16, 2018
roadmap Closes #345 - Erlang 21 support - Remove tuple calls (#351) Sep 22, 2018
src/Elchemy Closes #348 Prepare for elm 0.19 (#350) Sep 22, 2018
stable 0.5.0 / 2017-10-29 Oct 29, 2017
templates Closes #345 - Erlang 21 support - Remove tuple calls (#351) Sep 22, 2018
tests Closes #348 Prepare for elm 0.19 (#350) Sep 22, 2018
.gitattributes gitattr Apr 29, 2017
.gitignore Closes #276 macro plugins (#331) May 16, 2018
.gitmodules new name Jul 7, 2017
.tool-versions ASDF support Sep 22, 2018
.travis.yml Closes #348 Prepare for elm 0.19 (#350) Sep 22, 2018
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md (#304) Mar 11, 2018
ISSUE_TEMPLATE Fixes to ISSUE TEMPLATE inspired by #218 Nov 8, 2017
LICENSE Create LICENSE Aug 24, 2017
Main.elm Closes #348 Prepare for elm 0.19 (#350) Sep 22, 2018
Makefile Closes #348 Prepare for elm 0.19 (#350) Sep 22, 2018
README.md Update README.md Sep 22, 2018
book.json Closes #285 - Gitbook without summary (#286) Feb 6, 2018
bump.sh Closes #276 macro plugins (#331) May 16, 2018
elchemy 0.8.0 / 2018-09-22 Sep 22, 2018
elchemy_node.js HOTFIX: No Error on empty files (#266) Jan 30, 2018
elm-package.json Closes #220 cross referrence let in (#224) Nov 24, 2017
elmchemy Deprecation notice on elmchemy Aug 24, 2017
logo.png Improvements to docs page build (#212) Nov 8, 2017
mix.exs 0.8.0 / 2018-09-22 Sep 22, 2018
package.json 0.8.0 Sep 22, 2018
yarn.lock Uncurried function application when all args provided (#201) Oct 2, 2017

README.md

Quick install

npm install -g elchemy

What is it?

Elchemy lets you write simple, fast and quality type safe code while leveraging both the Elm's safety and Elixir's ecosystem

Test Elchemy online here or here Old (stable, no type checking) version

Read Elchemy documentation here

Read a tutorial on using Elchemy here

Read our DevBlog on Medium here

In case of any questions about the project feel free to submit them in Issues with Q&A label

Features

  • Type inference: Powerful type inference means you rarely have to annotate types. Everything gets checked for you by the compiler
  • Easy and type-safe interop: You can call Elixir/Erlang without any extra boiler-plate. All the calls you make are checked in terms of type-safety as thoroughly as possible based on Elixir's typespecs.
  • All the best of Elm and Elixir: Elchemy inherits what's best in Elm - type safety, inference and extreme expressiveness, but also what's best in Elixir - Doc-tests, tooling and obviously the entire BEAM platform.
  • Nearly no runtime errors - Elchemy's type system eliminates almost all runtime errors. With a shrinking set of edge cases, your entire Elchemy codebase is safe. Elixir parts of the codebase are the only ones to be a suspect in cases of runtime errors happening.
  • Beautiful and fully readable output - The produced code is idiomatic, performant and can be easily read and analyzed without taking a single look at the original source.

Usage

Prerequisites

Installation in Elixir project

Install elchemy globally with

npm install -g elchemy

Then in root of your project do:

elchemy init

And follow the instructions

elchemy will find all *.elm files specified in elchemy_path and compile it into corresponding *.ex files in lib directory.

You can override output directory specifying elixirc_paths.

Installation as a standalone

npm install -g elchemy

Usage

elchemy compile source_dir output_dir

Recommended editors setup

Build from source

git clone https://github.com/wende/elchemy.git
cd elchemy
make compile
./elchemy compile source_dir output_dir

and

make dev

To launch and test the web demo

Contributing Guide

Targeted values:

  • Fully readable and indented elixir code generated from compilation
  • Seamless and stress less interop with existing Elixir code, preferably with magically working type safety
  • Full integration with entire elm syntax for editors and compilers magic

Troubleshooting

If anything doesn't work, try

npm install -g elchemy
elchemy clean
elchemy init
mix test

first

FAQ

Why would I want to use that?

  • You like types
  • But even more you prefer compile-time errors over run-time error
  • You prefer add b c = b + c over defp add(a, b), do: b + c
  • You like curry
  • You think failing fast is cool, but not as cool as not failing at all

Why wouldn't I want to use that?

  • Your project relies on die-hard battle tested libraries, and you despise any versions starting with 0
  • You're afraid that when you learn what Monad is your mustache will grow, and eyesight weaken

Can I use it in already existing Elixir project?

You can, but nice and dandy compile tools are still on their way

Will my employer notice I'm having an affair with Elchemy?

The output files of Elchemy treat the code readability as a first class citizen. The code is meant to be properly indented, the comments aren't omitted, and the code is optimized as hard as it can ( f.i case clauses reduce to function overloads)

When will Elchemy become 1.0.0?

When it's done

Can I contribute?

Definitely. Yes. Please do.

How are types represented?

You're a nosy one, aren't you? Elchemy represents all type constructors as snake cased atoms, and all type applications as tuples. Which means that MyType 42 "Forty two" Error in Elchemy equals to {:my_type, 42, "Forty Two", :error} in Elixir.

Can I use already existing Elm libraries with Elchemy?

As long as they don't use any Native modules, Ports or Elm runtime they can be safely imported and used

Can I use already existing Elixir libraries with Elchemy?

Yes. You can do an ffi call to any function in any module. Whether it's Elixir module, Erlang module, or even a macro you can include it in your code. Ffi calls are a treated specially in Elchemy, and they get generated test to analyze the types based on @specs, so that you don't compromise type safety for using Elixir code. In order to increase readability it's advised not to use ffi calls if not necessary and always document and doctest them.

But what about out of function macros? Like tests and use Module?

Unfortunately you can't write any macros with do..end blocks yet. You can write any out of function code using an elixir inline code with:

{- ex
  code_here
-}

But it's a last resort solution and shouldn't ever be abused.

Can I define an Elixir macro in Elchemy?

So you want to write an Elm-like code, that will manipulate Elixir code, which generates an Elixir code that manipulates Elixir code? How about no?

Do I need to have Elm installed to compile my .elm files with Elchemy?

Elchemy uses Elm to typecheck your program. It is possible to use it without Elm on your machine, while it's not advised.

Maturity of the project

  • Parser - 99% of Elm's syntax (see elm-ast)
  • Compiler - 90% (Sophisticated incremental compilation. No support for Windows yet though (#287) also big reliance on unix tools (#288)
  • Elchemy-core - 95% ( Everything covered except side effects and JSON Decoders)
  • Interop with Elixir - 90% - Purity tests (#162) and handling of macro-heavy libraries (#276) to go
  • Ideology - 70% - We've got a pretty solid idea of where Elchemy is going
  • Documentation - 80% - There are two tutorials and a complete Gitbook documentation. Few entrance level tutorials though
  • Elchemy-effects - 20% - You can't and shouldn't write anything with side-effects in Elchemy yet. We're working on finding the best solution for effects that would fit both Elm's and Elixir's community (see #297 for more info)
  • Elchemy-core for Erlang VM - 5% (Everything for os related tasks like filesystem, OTP goodies etc are yet to be done)

Contributor credits: