grin-compiler/grin

GRIN is a compiler back-end for lazy and strict functional languages with whole program optimization support.

1,080

stars

1,930

commits

Haskell

primary language

Jun 13, 2025

updated

grin-compiler.github.io/
compiler
data-flow-analysis
functional-programming
haskell
llvm
optimisation

README

GRIN

Build Status Coverage Status Gitter chat

The name GRIN is short for Graph Reduction Intermediate Notation, and it is an intermediate language for graph reduction. GRIN is the optimizer and code generator component of the GRIN Compiler project which includes language frontends for Haskell, Idris and Agda. To get the big picture of the project check the project website. For an overview of the optimizer read The GRIN Project paper. To grasp the details take your time and read Urban Boquist's PhD thesis on Code Optimisation Techniques for Lazy Functional Languages .

Presentations

  • We presented the core ideas of GRIN at Haskell Exchange 2018. slides video
  • The Next-gen Haskell Compilation Techniques (2021) presentation gives a high-level overview of the project motivation. slides video

Read our paper A modern look at GRIN, an optimizing functional language back end (2019) to get an overview of GRIN related projects and other whole program compilers i.e. Boquist GRIN, UHC, JHC, LHC, HRC, MLton

Also check the GRIN transformation example from Boquist PhD and an example from our implementation.

Support

The project is supported by these awesome backers. Special thanks to our gold sponsors:

Sam Griffin

Holmusk logo

If you'd like to join them, please consider become a backer or sponsor on Patreon.

GRIN IR

Showcase

Setup

Installing LLVM

Homebrew

Example using Homebrew on macOS:

$ brew install llvm-hs/llvm/llvm-7

Debian/Ubuntu

For Debian/Ubuntu based Linux distributions, the LLVM.org website provides binary distribution packages. Check apt.llvm.org for instructions for adding the correct package database for your OS version, and then:

$ apt-get install llvm-7-dev

Nix

To get a nix shell with all the required dependencies do the following in the top level folder.

nix-shell

To run the example do the following from the top level folder.

(cd grin; cabal run grin -- grin/opt-stages-high-level/stage-00.grin)

To run a local Hoogle server with Haskell documentation do the following.

hoogle server --port 8087 1>/dev/null 2>/dev/null&

Build GRIN

stack setup
stack build

Usage

stack exec -- grin grin/grin/opt-stages-high-level/stage-00.grin

How to Contribute

See: Issues / Tasks for new contributors Keep it simple: We follow the fundamentals laid down in HaskellerZ - Feb 2018 - Getting things done in Haskell

Example Front-End

Read about how to generate GRIN code from a frontend language.

Also check the corresponding source code.

i.e.

Simplifying Transformations

Optimising Transformations

Contributors

csabahruska

985 commits

andorp

500 commits

Anabra

393 commits

LightAndLight

15 commits

grin-compiler/grin

GRIN is a compiler back-end for lazy and strict functional languages with whole program optimization support.

1,080

stars

1,930

commits

Haskell

primary language

Jun 13, 2025

updated

grin-compiler.github.io/
compiler
data-flow-analysis
functional-programming
haskell
llvm
optimisation

README

GRIN

Build Status Coverage Status Gitter chat

The name GRIN is short for Graph Reduction Intermediate Notation, and it is an intermediate language for graph reduction. GRIN is the optimizer and code generator component of the GRIN Compiler project which includes language frontends for Haskell, Idris and Agda. To get the big picture of the project check the project website. For an overview of the optimizer read The GRIN Project paper. To grasp the details take your time and read Urban Boquist's PhD thesis on Code Optimisation Techniques for Lazy Functional Languages .

Presentations

  • We presented the core ideas of GRIN at Haskell Exchange 2018. slides video
  • The Next-gen Haskell Compilation Techniques (2021) presentation gives a high-level overview of the project motivation. slides video

Read our paper A modern look at GRIN, an optimizing functional language back end (2019) to get an overview of GRIN related projects and other whole program compilers i.e. Boquist GRIN, UHC, JHC, LHC, HRC, MLton

Also check the GRIN transformation example from Boquist PhD and an example from our implementation.

Support

The project is supported by these awesome backers. Special thanks to our gold sponsors:

Sam Griffin

Holmusk logo

If you'd like to join them, please consider become a backer or sponsor on Patreon.

GRIN IR

Showcase

Setup

Installing LLVM

Homebrew

Example using Homebrew on macOS:

$ brew install llvm-hs/llvm/llvm-7

Debian/Ubuntu

For Debian/Ubuntu based Linux distributions, the LLVM.org website provides binary distribution packages. Check apt.llvm.org for instructions for adding the correct package database for your OS version, and then:

$ apt-get install llvm-7-dev

Nix

To get a nix shell with all the required dependencies do the following in the top level folder.

nix-shell

To run the example do the following from the top level folder.

(cd grin; cabal run grin -- grin/opt-stages-high-level/stage-00.grin)

To run a local Hoogle server with Haskell documentation do the following.

hoogle server --port 8087 1>/dev/null 2>/dev/null&

Build GRIN

stack setup
stack build

Usage

stack exec -- grin grin/grin/opt-stages-high-level/stage-00.grin

How to Contribute

See: Issues / Tasks for new contributors Keep it simple: We follow the fundamentals laid down in HaskellerZ - Feb 2018 - Getting things done in Haskell

Example Front-End

Read about how to generate GRIN code from a frontend language.

Also check the corresponding source code.

i.e.

Simplifying Transformations

Optimising Transformations

Contributors

csabahruska

985 commits

andorp

500 commits

Anabra

393 commits

LightAndLight

15 commits

Languages

Haskell

86.6%

LLVM

4.4%

Assembly

4.4%

C++

2.3%