Live data from Hacker News

Intel Haskell Research Compiler

github.com

11–20 of 39 posts

Re: Intel Haskell Research Compiler

#11
post #8

How ironic is it that the Haskell Research Compiler is written in Standard ML, and not Haskell? Joking aside, SML is a great language, and often overlooked, so this is good to see!

Word I heard was that it was originally designed as a compiler for both Standard ML and Haskell. I think the Haskell part only came later.

Re: Intel Haskell Research Compiler

#13
post #3

Wait... what? "To actually compile a Haskell program, we'll also need a patched version of GHC. See Building and Using GHC with HRC for more information."

Think of this as closer to an optimizing backend for GHC than a completely brand-new compiler. It uses GHC to parse, typecheck and desugar Haskell to an intermediate form called Core and uses that to do its own optimization and code generation.

A core design principle of Haskell is that while the whole language has gotten relatively complex thanks to all its language features and extensions, almost everything can be simplified to a really small and elegant core language. This core language is a typed lambda calculus that looks a lot like a subset of Haskell except with a few changes like no type inference and different rules for strictness.

GHC then uses this pared down version of Haskell (appropriately called Core) for the rest of its optimization and compilation. This means that once the first pass is done with type inference, type checking, typeclass resolution and a lot of other high-level transformations, the rest of the compiler doesn't have to worry about them at all. This makes all of GHCs optimizations easier to implement and maintain, and it lets us add features to Haskell without needing to change the backend.

Re: Intel Haskell Research Compiler

#14
post #4
post #3

Wait... what? "To actually compile a Haskell program, we'll also need a patched version of GHC. See Building and Using GHC with HRC for more information."

I think they use GHC frontend to parse Haskell sources.

Not only parse but do all the type-checking I guess (which is where Haskell is moving the most)

Re: Intel Haskell Research Compiler

#15
post #13
post #3

Wait... what? "To actually compile a Haskell program, we'll also need a patched version of GHC. See Building and Using GHC with HRC for more information."

Think of this as closer to an optimizing backend for GHC than a completely brand-new compiler. It uses GHC to parse, typecheck and desugar Haskell to an intermediate form called Core and uses that to do its own optimization and code generation. A core design principle of Haskell is that while the whole language has gotten relatively complex thanks to all its language features and extensions, almost everything can be…

If anyone's interested, there's a pretty well written book about the implementation:

https://www.microsoft.com/en-us/research/publication/the-imp...

Re: Intel Haskell Research Compiler

#16
post #12
post #8

How ironic is it that the Haskell Research Compiler is written in Standard ML, and not Haskell? Joking aside, SML is a great language, and often overlooked, so this is good to see!

About as ironic as Java or C++ being written in C.

Not quite; Hotspot (Sun/Oracle JVM) and Android Runtime are both C++; the major C/C++ implementations (GCC, LLVM/Clang, MSVC, Intel C++ Compiler) are all C++ too, although GCC was C until 2010 and MSVC's 16-bit ancestors were as well.

Re: Intel Haskell Research Compiler

#17
post #13
post #3

Wait... what? "To actually compile a Haskell program, we'll also need a patched version of GHC. See Building and Using GHC with HRC for more information."

Think of this as closer to an optimizing backend for GHC than a completely brand-new compiler. It uses GHC to parse, typecheck and desugar Haskell to an intermediate form called Core and uses that to do its own optimization and code generation. A core design principle of Haskell is that while the whole language has gotten relatively complex thanks to all its language features and extensions, almost everything can be…

Core, C--, LLVM… — how many intermediate languages is it going through?!

Re: Intel Haskell Research Compiler

#18
post #10

In essence, a big reason why the Intel team was able to do this was because they're getting optimized IR from GHC's front-end[0], and then applying further optimizations with their compiler (HRC) and then converting it into yet another IR (MIL) used by yet another compiler (FLRC), designed by Intel for arbitrary functional programming languages, for some further optimizations and ultimately into C where Intel's C com…

The talk you linked to is quite enjoyable, thank you!

Re: Intel Haskell Research Compiler

#19
post #11
post #8

How ironic is it that the Haskell Research Compiler is written in Standard ML, and not Haskell? Joking aside, SML is a great language, and often overlooked, so this is good to see!

Word I heard was that it was originally designed as a compiler for both Standard ML and Haskell. I think the Haskell part only came later.

Haskell was the second frontend. Don't think we ever did a SML frontend. We can't really discuss what the original frontend was so it was scrubbed from the release.

Re: Intel Haskell Research Compiler

#20
post #3

Wait... what? "To actually compile a Haskell program, we'll also need a patched version of GHC. See Building and Using GHC with HRC for more information."

Keep in mind that GHC/Haskell has a gazillion extensions, so parsing Haskell directly is fairly complex.
Post reply on HN