Grain started as a passion project in 2017 by Philip Blair and Oscar Spencer, who wanted a high-level language that was easy to use and designed to compile to WebAssembly (Wasm).
The Birth of Grain
In 2017, Philip Blair and Oscar Spencer aimed to create a language specifically for WebAssembly. Spencer recalled the early days: “A buddy and myself got together, and we said, let’s make this thing target Wasm. We got our first host functions working, being able to call in the browser, make buttons do things, and we were really excited. That was just the birth of the project.”
Goals and Progress
Grain released version 0.6 in March, with the core team expanding over time. The goal remains to create a high-level language that developers enjoy using every day. Spencer emphasized, “It’s not for some huge commercial enterprise. It’s more about building something we think is awesome. The core team has expanded. People think it’s interesting.”
Inspiration from OCaml
The team aimed to create a modern version of OCaml, a language from the ’90s known for features like pattern matching. Pattern matching allows the compiler to alert developers if an edge case is missed, reducing bugs. Spencer highlighted, “One of the funny things they say about OCaml is that if your code compiles, it’s correct. It might not do what you wanted, but it’s doing what it’s supposed to do.”
Grain vs. Other Languages
Grain’s syntax is familiar to React developers due to similarities with JavaScript. “If you’re coming from JavaScript, you’ll feel comfortable with the syntax. You’ll feel comfortable with some of the ideas of functional programming,” Spencer explained. Unlike JavaScript, Grain supports functional programming from the beginning, leading to smaller modules when compiled to Wasm.
WebAssembly and Grain
WebAssembly (Wasm) is a high-level assembly language that lacks traditional stack introspection. This means you can’t look at the current stack, a feature that Grain embraced. “We’re targeting WebAssembly, so we assume we’re not going to have stack introspection. Let’s just work with the primitives we have,” Spencer said.
Benefits and Limitations
Grain excels in writing business logic and solving problems efficiently with features like pattern matching. However, it’s less effective for low-level tasks like writing cryptography libraries. “It’s very data first… We’ve got things like pattern matching to deal with different ways that folks are going to interact with the data,” Spencer noted.
Future Developments
Grain is moving towards supporting components, a new specification that sits on top of the core WebAssembly specification. This involves adhering to the canonical ABI, which defines the encoding of Wasm components. “For a language to support the component model, it must adhere to this canonical ABI,” Spencer explained.


