https://github.com/elm-in-elm/compiler Skip to content Sign up * Why GitHub? Features - + Mobile - + Actions - + Codespaces - + Packages - + Security - + Code review - + Issues - + Integrations - + GitHub Sponsors - + Customer stories- * Team * Enterprise * Explore + Explore GitHub - Learn and contribute + Topics - + Collections - + Trending - + Learning Lab - + Open source guides - Connect with others + The ReadME Project - + Events - + Community forum - + GitHub Education - + GitHub Stars program - * Marketplace * Pricing Plans - + Compare plans - + Contact Sales - + Education - [ ] [search-key] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this organization All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} elm-in-elm / compiler * Notifications * Star 296 * Fork 15 Elm compiler written in Elm elm-in-elm.github.io/compiler/ BSD-3-Clause License 296 stars 15 forks Star Notifications * Code * Issues 11 * Pull requests 7 * Actions * Security * Insights More * Code * Issues * Pull requests * Actions * Security * Insights master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 6 branches 2 tags Code Clone HTTPS GitHub CLI [https://github.com/e] Use Git or checkout with SVN using the web URL. [gh repo clone elm-in] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching Xcode If nothing happens, download Xcode and try again. Go back Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @Janiczek Janiczek Add integration test for type inference of mutual recursion ... 27dbb9c Jul 13, 2021 Add integration test for type inference of mutual recursion 27dbb9c Git stats * 379 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github Upgrade to GitHub-native Dependabot (#124) Apr 29, 2021 assets Current state of library Oct 16, 2019 benchmarks/findDuplicatesBy Bump elm-community/list-extra in /benchmarks/findDuplicatesBy (#126) Jun 7, 2021 cli Bump elm/project-metadata-utils from 1.0.1 to 1.0.2 in /cli (#122) Apr 6, 2021 dev-progress Update progress Jul 5, 2020 example-library-usages Bump elm/project-metadata-utils in /example-library-usages (#123) Apr 6, 2021 example-project Implement typechecking of vars (across declarations) Jul 13, 2021 integration-tests Add integration test for type inference of mutual recursion Jul 13, 2021 review Implement typechecking of vars (across declarations) Jul 13, 2021 src Fix library wrt new inferTypes stuff Jul 13, 2021 tests Add test for f a b c < 5 Jul 13, 2021 .gitignore Let's try github actions May 13, 2020 .travis.yml Upgrade deps in travis script Nov 30, 2019 LICENSE Awkwarddddd Mar 31, 2019 Makefile Implement typechecking of vars (across declarations) Jul 13, 2021 README-library.md Make docs better Oct 10, 2019 README.md Update progress Jul 5, 2020 elm-analyse.json elm-analyse lint Apr 1, 2019 elm-tooling.json Add bugs found from discussion in Elm Slack; elm-tooling Jun 3, 2021 elm.json Use elm-test-rs and fix Makefile and package.json Jul 12, 2021 library-todo.txt TODO Oct 10, 2019 package.json Implement typechecking of vars (across declarations) Jul 13, 2021 shell.nix Update nix-shell Jul 13, 2021 watch-compile.sh Implement typechecking of vars (across declarations) Jul 13, 2021 watch-test.sh Implement typechecking of vars (across declarations) Jul 13, 2021 yarn.lock Implement typechecking of vars (across declarations) Jul 13, 2021 View code elm-in-elm Goals Non-goals What? Contributing Roadmap FAQ Prerequisites Running the compiler Running the tests Formatting code Small TODOs Project management General Type inference Optimizations PrepareForBackend Emit Tests Contributors License Attribution README.md elm-in-elm logo elm-in-elm Elm compiler written in Elm! [6874747073] [6874747073] [6874747073] [6874747073] [6874747073] [6874747073] [6874747073] [6874747073] [6874747073] --------------------------------------------------------------------- Goals 1. compiler as Elm library: so that we can publish it on https:// package.elm-lang.org/ and unlock new kinds of Elm applications (like Elm-evaluating Slack bots, Klipse integration, stepping debuggers, ...)! 2. learning friendly: so that folks can learn how to write a compiler in Elm (similarly to Richard Feldman's elm-spa-example). This means elm-in-elm is focused on readability, beauty, approachability, simplicity, great docs and great tests first, and only then completeness and speed. 3. exploration ready: the first two points enable folks to hack on the compiler (as it's written in Elm, which they know, and the code is new-people-friendly) and answer some questions! (For example, what's the best order of optimizations? How would emitting to JavaScript have to look like to make it extra amenable to Google Closure Compiler's advanced optimizations?) 4. extensible: again, the first two (three?) points make it easy and invite extending the compiler in various ways, eg. a native binary target, different type inference algorithm, new optimizations, where syntax, etc. In short, elm-in-elm aims to unblock and encourage people to play with compilers and the Elm language itself, explore new frontiers and have fun! For more context and information, you can watch Martin Janiczek's talk from Elm Europe 2019 which served as an unveiling of elm-in-elm to public. Here are the slides. Non-goals 1. To dethrone or replace the official Elm compiler written in Haskell. This is NOT THE REASON and NOT THE GOAL of elm-in-elm. We don't want to and aren't planning to divide the community into multiple Elm derivatives, and will actively try to prevent that. elm-in-elm is, for all intents and purposes, a sandbox, a place to try out ideas, an experimentation environment. What? elm-in-elm consists of: * a compiler implementation * a library * a CLI tool * and a test suite. It is written in Elm, and compiles Elm to JavaScript, but lays the foundation to be able to compile to different targets in the future. [?][?] Warning! elm-in-elm is definitely not ready for usage yet, even though its library is published already. The main blocker is the parsers for expressions not being all implemented yet. See the parse column in the table below. Contributing Please yes! [?] Feel free to look around the help wanted or good first issue issues, have a look around the codebase for some general nitpicks or refactorings, or hit us up on Discord! Roadmap Roadmap parser optimize emit parse desugar infer optimize emit tests tests tests types integers [?] [?][?] [2] [?] [?] [?] [?] [?][?] [2] [?] floats [?] [5] [?] [?] [?] [?] [5] [?] characters [?] [?] [?] [?] [?] [?] [?] [?] strings [?] [?] [?] [?] [?] [?] [?] [?] booleans [?] [?] [?] [?] [?] [?] [?] [?] variables [?][?] [?] [?] [?] [?] [?] [?] [?] lists [?] [6] [?][?] [?] [?] [?] [6] [?][?] [1] [1] binary operators [?][?] [3] [?] [?] [?][?] [?] [?][?] [?][?] [3] lambdas [?] [?] [?] [?] [?] [?] [?][?] [?] function calls [?] [?] [?] [?] [?] [?] [?] [?] if...then...else [?] [?] [?] [?] [?] [?] [?] [?] let..in [?] [?] [?] [?] [?] [?][?] [?] [?][?] case...of [?][?] [4] [?][?] [4] records [?] [?] [?] [?] [?] [?] [?] [?] record accessors record updates unit type [?] [?] [?] [?] [?] [?] [?] [?] tuples, 3-tuples [?] [?] [?] [?] [?] [?] [?] [?] type annotations [?] [?] [?] [?] [?] [?] [?] [?] type aliases [?] [?] [?] [?] [?] [?][?] [?] [?] [7] custom types [?] [?] custom operators shaders (?) 1. Lists' emit will have to change a bit: conversion from target platform lists to Elm "custom type" lists is now missing; tracked in #29 2. To be optimized with multiplication, subtraction, division, modulo, exponentiation... maybe more? 3. Multi-line binops (probably) don't work correctly now 4. Custom type patterns aren't supported yet 5. To be optimized the same way Ints are 6. Not implemented; partially tracked in #29 7. We're currently doing nothing about the type parameters in the type aliases. FAQ 1. + Q: Why not use stil4m/elm-syntax for the parsers? + A: We'd love to use elm-syntax - it would save us so much trouble. But that would not be ideal in some regards: o less flexibility wrt. how our types look o would be less educational (compare with the learning resource goal) - would skip parsers entirely o even if we didn't use it as a library but copypasted the parsers code, those are written in the 0.18 elm-community /parser-combinators style - we'd like, again because of the learning resource goal, to have the parsers written in idiomatic elm/parser style But yeah, there's definitely a little bit of NIH syndrome happening Prerequisites The easy way: if you have Nix installed, run $ nix-shell and you'll drop into a shell that has all the dev dependencies set up and ready! Alternatively, this is what the project needs. * make for the Makefile * NodeJS 10+ for the CLI tool * elm, elm-test and elm-format Running the compiler $ make Essentially compiles the compiler (using the official Elm compiler ) to a build/elm.js file and runs it using node. Very handy for running the whole compiler pipeline on an example project living in example-project/, which the CLI is currently hardcoded to try and compile! In some cases this might be more convenient than writing tests - just add an interesting snippet to example-project/src/Main.elm, Debug.log what you need in the compiler itself, and make! So absolutely feel free to go bonkers on that example-project/ - it's there for developer convenience! Running the tests $ make test Runs elm-test on the test suite (gasp!) Formatting code $ make format Runs elm-format. Make sure to format code before submitting a pull request! Small TODOs This is a brain-dump of some low-level stuff. (High-level stuff should be in the roadmap.) My apologies if it's hard to make sense of this! ~janiczek Project management * [ ] @janiczek: Share your Firefox bookmarks relevant to elm-in-elm (ie. talks about Haskell hierarchical optimizations etc.) * [ ] Add tests for stages other than parsing and emit into the matrix above General * [ ] Compare our Main.compile with official compiler's Compile.compile - is that a better API? * [ ] Types module: remove, refactor into "module per datastructure" style? * [ ] Deal with kernel modules * [ ] Deal with ports * [ ] Deal with effect modules * [ ] Deal with typeclasses (number, comparable, ...) * [ ] Deal with pattern matching * [ ] Deal with custom binary operators Type inference * [ ] Try the Complete and Easy Bidirectional Typechecking for Higher-Rank Polymorphism and see where that leads * [ ] Let polymorphism : Stage.InferTypes.generateEquations, the Typed.Let case. This paper might have a parable written well enough that we might actually understand type schemes from this. Otherwise, "Write you a Haskell" for the rescue! There is also the Damas and Milner paper proving the inferred type is the most general one. * [ ] Extensible records (link): D. Leijen, "Extensible records with scoped labels," in Revised Selected Papersfrom the Sixth Symposium on Trends in Functional Programming, TFP 2005,Tallinn, Estonia, 23-24 September 2005.(M. C. J. D. van Eekelen, ed.), vol. 6 of Trends in Functional Programming, pp. 179-194, Intellect, 2005. * [ ] Typecheck across modules, not each module separately. This will probably be clearer after we try and implement the library. * [ ] Annotate type errors with position in source code (for better error messages) * [ ] Try to find a better name for "occurs check" and make the error message easier to understand * [ ] Document the typechecking stages better (ie. at all) * [ ] Rename types to be able to show nice type variables (ie. the classic a instead of type #0 or something). Stage.InferTypes.getType Optimizations * [ ] Experiment with Prepack-like optimization: compute everything you can in the compile-time instead of runtime * [ ] Implement constant propagation? * [ ] Implement inlining (maybe it will need some heuristic? Look at how other langs do it?) * [ ] Implement (<|) and (|>) fusion (eg. transform both x |> f and f <| x into f x) PrepareForBackend * [ ] Check that the Lambda case of Stage.PrepareForBackend.findDependencies works correctly Emit * [ ] Native binary target (x86_64), possibly through LLVM? * [ ] WebAssembly? * [ ] Would this simplify / be a good fit for Elchemy (Elm -> Elixir)? * [ ] Would this simplify / be a good fit for philip2 (Elm -> OCaml)? * [ ] Would it be worth concatenating single-arg lambdas back to multi-arg ones (so that we emit eg. (a,b) => a+b instead of (a) => (b) => a+b)? * [ ] How to emit let? How does official compiler do it? Seems the dependency graph will have to be computed for its binidng too, similarly to how the path to main gets computed for the program itself. Stage.Emit.emitExpr, the Let case. * [ ] Do we need to mangle variable names? (ie. do what the official compiler does) Maybe not! Check * [ ] What's good JS style for Google Closure Compiler's advanced optimizations? * [ ] What's good JS style for UglifyJS? * [ ] What's good JS style for modern JS engines? Tests * [ ] Test Common.unalias * [ ] Test Stage.Desugar.findModuleOfVar Contributors [149425] [5399281] [16308754] [197573] [16829510] Martin Remi Lefevre Harry Maxime Aaron Janse Janiczek Sarson Dantec [3983879] [6839698] [12603666] [15112020] [68747470733a2f2f7261] Eduard Sebastien sgdan Pablo You? Kyvenko Besnier Hirafuji License BSD-3-Clause Attribution * "person using laptop" icon created by alvaro_cabrera About Elm compiler written in Elm elm-in-elm.github.io/compiler/ Topics language compiler elm-lang Resources Readme License BSD-3-Clause License Releases 2 tags Packages 0 No packages published Contributors 14 * @Janiczek * @dependabot-preview * @harrysarson * @Warry * @sebsheep * @aaronjanse * @halfzebra * @dependabot * @szabba * @miniBill * @rlefevre + 3 contributors Languages * Elm 96.7% * JavaScript 2.3% * Other 1.0% * (c) 2021 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.