{"id":13341513,"url":"https://github.com/aionescu/wasm-hs","last_synced_at":"2025-07-25T16:34:06.335Z","repository":{"id":211627429,"uuid":"695620476","full_name":"aionescu/wasm-hs","owner":"aionescu","description":"Type-safe WebAssembly eDSL in Haskell","archived":false,"fork":false,"pushed_at":"2024-10-20T14:31:23.000Z","size":126,"stargazers_count":25,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-03T16:23:12.425Z","etag":null,"topics":["edsl","haskell","wasm","web-assembly"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aionescu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-23T18:11:51.000Z","updated_at":"2025-02-24T03:58:19.000Z","dependencies_parsed_at":"2023-12-09T20:25:36.395Z","dependency_job_id":"9cafeaf4-af84-4ef2-94c5-07df6e386031","html_url":"https://github.com/aionescu/wasm-hs","commit_stats":null,"previous_names":["aionescu/wasm-hs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aionescu/wasm-hs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aionescu%2Fwasm-hs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aionescu%2Fwasm-hs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aionescu%2Fwasm-hs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aionescu%2Fwasm-hs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aionescu","download_url":"https://codeload.github.com/aionescu/wasm-hs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aionescu%2Fwasm-hs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267030675,"owners_count":24024231,"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","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["edsl","haskell","wasm","web-assembly"],"created_at":"2024-07-29T19:25:28.871Z","updated_at":"2025-07-25T16:34:06.251Z","avatar_url":"https://github.com/aionescu.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- markdownlint-disable first-line-heading --\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003ewasm-hs\u003c/h1\u003e\n\n  \u003cimg src=\"assets/logo.png\" alt=\"wasm-hs Logo\" width=\"150\" height=\"150\"/\u003e\n\u003c/div\u003e\n\nThis project provides an embedded domain-specific language (eDSL) for encoding WebAssembly in Haskell in a type-safe way (i.e. writing invalid Wasm results in a Haskell type error).\n\nBelow is a simple example of the DSL, a Wasm program that computes the factorial of 5:\n\n```haskell\nfactorial :: WasmModule\nfactorial = wasm do\n  fn #factorial @'[Int] do\n    dup\n    const 1\n\n    if gt then do\n      dup\n      const 1\n      sub\n      call #factorial\n      mul\n    else do\n      drop\n      const 1\n\n  fn #main do\n    const 5\n    call #factorial\n    print\n```\n\n## Supported features\n\n* Arithmetic and comparison instructions\n* Blocks and structured control-flow\n* Local and global variables\n* Type-safe dynamic memory access\n* Functions, including mutual recursion\n\n## Ergonomics\n\nTo provide better ergonomics as a Haskell DSL, the project deviates from the WebAssembly specification in a few aspects:\n\n* The operand stack can contain values of any Haskell type, not just the Wasm primitive types (`i32`, `i64`, `f32`, `f64`).\n* Additional instructions are supported (`dup`, `swap`) that are not present in Wasm.\n* Arithmetic and comparison instructions are overloaded using the standard Haskell typeclasses (`Num`, `Ord` etc.).\n* Boolean instructions (comparisons, `br_if` etc.) use Haskell's native `Bool` type, rather than encoding booleans as `0` or `1` of type `i32`.\n* Local variables are scoped explicitly (using a `let'` instruction), instead of being function-scoped.\n* Memories are typed, and are scoped similarly to local variables (allocated with the `let_mem` instruction).\n\n## Interpreter\n\nThe project also includes an interpreter that uses continuation-passing style for efficient jumps, and local instances (via [`WithDict`](https://hackage.haskell.org/package/base/docs/GHC-Exts.html#t:WithDict)) for constant-time variable lookup.\n\nGlobal variables and memories can be initialised with host-provided mutable references (`IORef`s), which allows the host to pass input data to the Wasm module, and inspect its mutations after execution.\n\n## Limitations\n\n* The DSL only allows the construction of self-contained Wasm modules (i.e. no external imports or exports).\n* `call_indirect` and `br_table` are not supported.\n\n## Project structure\n\nThe main modules of the library are [`Language.Wasm.Instr`](src/Language/Wasm/Instr.hs), which defines the core `Instr` AST datatype and evaluation functions; and [`Language.Wasm.Module`](src/Language/Wasm/Module.hs), which builds upon `Instr` and defines a datatype for bundling definitions into modules, as well as module evaluation functions.\n\n[`Language.Wasm.Syntax`](src/Language/Wasm/Syntax.hs) defines the DSL's syntactic sugar, and [`Language.Wasm.Prelude`](src/Language/Wasm/Prelude.hs) ties everything together into a single import.\n\nThe [`Language.Wasm.Examples`](src/Language/Wasm/Examples.hs) module defines a number of example Wasm programs, and [`Main`](app/Main.hs) contains the driver code.\n\n## Dependencies\n\n* GHC \u003e=9.8.1\n* Cabal \u003e=3.10.2.0\n\n(Both can be installed via [GHCup](https://www.haskell.org/ghcup/))\n\n## Building and running\n\nThe project has no external (non-Haskell) dependencies, and can simply be built using `cabal`:\n\n```sh\ncabal build\n```\n\nRunning the project with no arguments will run all the example programs:\n\n```sh\ncabal run\n```\n\nIf you want to run only specific examples, pass their names as arguments:\n\n```sh\ncabal run . -- factorial fibonacci\n```\n\nIf you specify an example multiple times, it will be executed that many times. This can be used to observe side-effects such as mutating memory shared by the host:\n\n```sh\ncabal run . -- squareAll squareAll\n```\n\n## Running the tests\n\nTo run the library's test-suite, use the following command:\n\n```sh\ncabal run wasm-hs-test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faionescu%2Fwasm-hs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faionescu%2Fwasm-hs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faionescu%2Fwasm-hs/lists"}