{"id":13565196,"url":"https://github.com/forest-lang/forest-compiler","last_synced_at":"2025-04-03T22:30:50.980Z","repository":{"id":88103259,"uuid":"110298402","full_name":"forest-lang/forest-compiler","owner":"forest-lang","description":"A multi-syntax functional programming language that compiles to WebAssembly.","archived":false,"fork":false,"pushed_at":"2021-08-04T11:47:12.000Z","size":668,"stargazers_count":619,"open_issues_count":8,"forks_count":13,"subscribers_count":44,"default_branch":"master","last_synced_at":"2024-11-04T18:46:31.134Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/forest-lang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-11-10T22:26:17.000Z","updated_at":"2024-10-01T10:57:36.000Z","dependencies_parsed_at":"2023-05-18T07:45:49.122Z","dependency_job_id":null,"html_url":"https://github.com/forest-lang/forest-compiler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forest-lang%2Fforest-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forest-lang%2Fforest-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forest-lang%2Fforest-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forest-lang%2Fforest-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/forest-lang","download_url":"https://codeload.github.com/forest-lang/forest-compiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247089893,"owners_count":20881873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T13:01:42.385Z","updated_at":"2025-04-03T22:30:48.954Z","avatar_url":"https://github.com/forest-lang.png","language":"Haskell","funding_links":[],"categories":["Haskell"],"sub_categories":[],"readme":"# forest-lang\n\nForest is a functional programming language that compiles to WebAssembly. This repository contains the compiler and core syntaxes, currently implemented in Haskell.\n\nForest is pre-alpha experimental conceptual research software. Imagine this documentation as a preview of what Forest might be.\n\nDesign principles\n----\n\n* Ease of collaboration outweighs all other priorities.\n* For the sake of collaboration, we agree on structure and semantics, and agree to disagree on syntax.\n* Forest will be fast enough to make complex games, so normal web apps will be blazing fast.\n* Testing aids collaboration, so it should be as painless as possible.\n* Since we want to write tests, effect execution and logic should be separate.\n* What if everything was a dataflow graph?\n\nFeatures\n-----\n\n * Statically typed\n * Pattern matching\n * Immutable datastructures (with mutable optimizations for common cases)\n * Ref-counted, incremental cleanup that can be scheduled. No automatic stop the world GC.\n * Multiple syntaxes, users can create and customize syntaxes, and project between.\n * Automatic code formatting\n * Dev virtual filesystem powered by FUSE to project code into desired syntax.\n * Visual editor\n \nFAQ\n---\n\n**Why are you making this? What's your point of difference from other languages?**\n\nA few reasons. I work on Cycle.js and build apps with it. I wanted to build a visual editor for Cycle.js, but also wanted to be able to edit a textual representation. Rather than retrofitting a complex system to enable that on top of a language with suboptimal semantics, I preferred to start fresh.\n\nI also started working more with Elm, and while I like many aspects of Elm's type system and syntax, I missed being able to build applications as dataflow graphs.\n\nOn top of all of that, I have a keen interest in making games on the web, but I am frustrated by the memory model in JavaScript. The hiccups introduced by uncontrollable stop the world garbage collection tear at my soul. I view WebAssembly as an amazing opportunity to eliminate much of the cruft that bloats the web platform.\n\n**What does the syntax look like?**\n\nSince Forest supports multiple syntaxes, it might look very different to different developers.\n\nThe first syntax in development is inspired by Haskell and Elm.\n\nFor example, here is fibonacci implemented in Forest:\n\n```elm\nfib i =\n  case i of\n    0 -\u003e 1\n    1 -\u003e 1\n    i -\u003e fib (i - 2) + fib (i - 1)\n```\n\nHowever, this could just as easily be written using another syntax more comparable to JavaScript:\n\n```js\nfunction fib(i) {\n  switch (i) {\n    case 0: 1;\n    case 1: 1;\n    case i: fib(i - 2) + fib(i - 1);\n  }\n}\n```\n\nNotice that while the syntax in these examples differs, the underlying semantics are the same (implicit returns, pattern matching).\n\n**If every dev can use different syntax, what do we store in the repo?**\n\nYou only need to store a single representation of the syntax in source control, which we'll call the canonical representation. The syntax for this representation would be agreed by the project's collaborators, but is largely unimportant.\n\n**What's the point of having different syntaxes?**\n\nSyntax is polarising. I know people who love Ruby's syntax, and people who hate it. I know people who love Haskell syntax, and people who hate it. The syntax of your language immediately alienates a large swathe of the community.\n\nBeyond languages, the arguments go on. Tabs vs spaces? Whitespace sensitive or curly braces? Semicolons or not?\n\nIf everyone can use the syntax they desire, we don't need to have those arguments anymore. How much time does your team spend talking style?\n\nIn current languages, new syntax is headline news. Some of the best parts of ES2015 were simply syntactic sugar. If we push syntax to userland, each developer can have their preferred sugar and we can iterate without the need for major version changes to languages.\n\nAdditionally, having a variety of different syntaxes might aid beginners in learning the language and contributing to projects. Maybe the maintainers of a project personally like the Haskell syntax with the [sweet unicode greek alphabet generics](https://hackage.haskell.org/package/wai-cors-0.2.5/docs/src/Network.Wai.Middleware.Cors.html#sshow), but perhaps a new contributor is more accustomed to a Python style syntax. Why shouldn't they be able to work together?\n\n**Won't the docs be in a different syntax than what I prefer? What about code snippets?**\n\nA medium term goal is for the Forest compiler to be written in Forest. This means syntaxes will also be written in Forest, which means we can run them in a web browser. So it would be possible to display docs in your preferred syntax, or at least your favourite core syntax. As for code snippets, we could build a code snippet sharing website that projects the snippet to your preferred syntax.\n\n**How do I edit the code in my preferred syntax? Do I need an editor plugin?**\n\nWhen working on the project, each developer runs `forest dev`, which mounts a virtual filesystem in the local directory using FUSE, called `dev/`.\n\n`dev/` contains all of the source files, projected into the developer's syntax of choice. The developer can read and write these files using their text editor of choice, modifying the canonical representation, with no need to install an editor plugin. Their syntax automatically generates syntax highlighting files for all common editors.\n\n**What about reviewing changes in the command line and web?**\n\nSource control tools such as git can be configured to diff using `forest diff`, which shows the diffs in the developer's preferred syntax.\n\nWhen reviewing pull requests on the web, developers use WebExtensions to project the changes to their preferred syntax.\n\n**Aren't immutable data structures memory innefficient? Won't that limit your performance with complex games?**\n\nImmutable data structures can have suboptimal characteristics for some classes of high performance applications. This is due to the need to allocate new memory for every change, and in garbage collected languages the need to cleanup unused previous structures.\n\nIn Forest, a simple reference counting strategy is used to keep track of allocated memory. When an immutable update is performed, if there is only a single reference to the memory that is being updated, we can simply update the memory in-place. This saves the need to garbage collect the old version that is no longer referenced.\n\nForest will automatically free any memory when it is no longer referenced. By default, this happens automatically as the code executes. Users can optionally disable this and instead run incremental cleanup for a specified number of milliseconds. In applications trying to maintain a smooth framerate, this allows for fine control over cleanup pauses.\n\n**Why compile directly to WebAssembly? Why not compile to LLVM and get WASM support for free, along with many other platforms?**\n\nThere are a few reasons for this. The first is that I'm interested in learning about WebAssembly, and compiling to it is a great way to learn how it works. The second is that Forest aims to squeeze as much performance out of the browser as is reasonably possible. Compiling directly to WebAssembly means we can ensure we produce the smallest reasonable number of instructions to run a program.\n\nSupport for compiling to other platforms is planned, as Forest aspires to be a general purpose language. However, the web comes first.\n\n**How close is Forest to being ready for real use?**\n\nForest is just a sprout right now, it has a long way to go.\n\nRight now, it supports:\n * numbers\n * infix arithmetic\n * function declaration and calls\n * pattern matching\n * let expressions\n * auto code formatting!\n * strings!\n * memory management (kinda)\n * a type system (simple but there)\n * ADTs\n * lists\n\nCritical missing features:\n  * an effect system\n  * a standard library of data structures\n  * a module system\n  * a way to install and share packages\n\nSo, very not ready for even simple applications.\n\nUsing Forest\n---\n\nFirst, you'll need to make sure you have [Stack](https://docs.haskellstack.org/en/stable/README/) and [Nix](https://nixos.org/nix/download.html) installed.\n\nNext, clone this project and run `make`. If you want to make changes and submit a pull request, make a fork and clone that.\n\n```\ngit clone https://github.com/forest-lang/forest-compiler.git\n\ncd forest-compiler\n\nmake\n```\n\n`make` will build Forest and copy the binary to your path. It will also run the tests.\n\nForest has a single binary right now, named `forest`. It has two commands, `forest build \u003cfile\u003e`, which produces text-format WebAssembly, and `forest format \u003cfile\u003e`, which reprints the given file to stdout.\n\nTo run the generated Wast, you can either use the provided `wasm-interp` script, run it yourself with Node, or in a WebAssembly compatible browser.\n\nSee [MDN](https://developer.mozilla.org/en-US/docs/WebAssembly/Using_the_JavaScript_API) for more info.\n\nThis is a rough experience right now, and is an area that should be better.\n\n**I have a question not answered here?**\n\nPlease [open an issue](https://github.com/forest-lang/forest-compiler/issues/new) and ask questions, offer to help, point out bugs or suggest features.\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fforest-lang%2Fforest-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fforest-lang%2Fforest-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fforest-lang%2Fforest-compiler/lists"}