Skip to content
0:00 / 0:00

#ghccore#systemf#haskell

Into the Core - Squeezing Haskell into Nine Constructors by Simon Peyton Jones

Erlang Solutions

18K subscribers • 39 videos on Hallway

YouTube
  • Recommended by 4 people: 1 on Lobsters, 2 in engineering communities and 1 curated list.
  • A classic. People kept recommending it from 2016 to 2021.
  • Presented by Simon Peyton Jones, co-designer of Haskell

Advanced. Deep dive for people who know the field.

41K views10 years ago4 recommendations

Programming languagesSystems programmingHaskellCompilers and interpretersFunctional programming

Simon Peyton Jones explains GHC Core, the tiny, statically typed intermediate language that Haskell compiles down to.

Keynote talk from Erlang USer Conference 2016 erlang-factory.com/euc2016/ Erlang and Haskell are childhood friends who grew up together. Throughout the years, they have learnt a lot from each other. And just because they have become adults does not mean the learning stops. GHC translates all of Haskell into a tiny but super-expressive intermediate language called Core, does a lot of optimisations on Core, and then generates executable code. Core is statically typed, making GHC one of the very few production compilers that is statically typed all the way through to code generation. It pulls off this trick by drawing directly on System F, a mathematical calculus from type theory. Functional programming is amazing: serious theory leads directly to beautiful implementations. In this talk I’ll take you on a journey into Core and its design choices. I’ll sketch Core’s type system, and the optimisations that GHC implements in Core, including let-floating, strictness analysis, specialisation, inlining, and the case-of-case transformation. Haskell and Erlang are both functional languages, albeit with significant differences (strict vs lazy, untyped vs typed). I hope that the talk may lead to dialogue about how these similarities and differences show up in a compiler.

Why it's here

4 people recommend this

What people say. Widely recommended as a classic, brilliant explanation of compiler intermediate representations and GHC internals.

u/joehillenin r/haskell • Recommends

Into the Core - Squeezing Haskell into Nine Constructors by Simon Peyton Jones

u/hou32houin r/ProgrammingLanguages • Recommends

Into the Core - Squeezing Haskell into Nine Constructors by Simon Peyton Jones

unbalancedparentheseson Lobsters • Recommends

Into the Core: Squeezing Haskell into Nine Constructors by Simon Peyton Jones

programming-talkscurated list on GitHubRecommends

Under “Programming Language Design”

Into the Core - Squeezing Haskell into Nine Constructors 01:07:48 by **Simon Peyton Jones** (2016)

u/fond-of-rainin r/ProgrammingLanguages • Mentions

On “How do programming language designers manage language complexity?”

Like core in GHC! So cool. I use this technique extensively in my compiler too. Typechecking, constant folding, compile-time evaluation, and so on all occur on my core type.

u/bjzabaPikelet, Gluon, Unnamed Binary DDLin r/ProgrammingLanguages • Mentions

On “How and when do you project cutting edge proglang tech will become mainstream?”

GHC Haskell has been so adaptable because of very deliberate and careful design - all of the high level features desugar into a very simple core language based on System F. More can be seen in this talk by SPJ: link to this video Another success story would be Racket, with its flexible macro language.

u/SV-97in r/ProgrammingLanguages • Mentions

On “Is there a language that does multi-level optimization?”

GHC has user defined rewrite rules that offer what you want I think. IIRC it's this talk where SPJ explains them(somewhere towards the end): [video

u/thmproverin r/ProgrammingLanguages • Mentions

On “Haskell-like language.”

Also good is: - The implementation of the Gofer functional programming system by Mark P. Jones - Write Yourself a Haskell... in Lisp **Edit.** Oh I also forgot Hinze's The categorical abstract machine: Basics and enhancments walks through compiling a lambda calculus plus algebraic data types to CAM bytecode; and Into the Core - Squeezing Haskell into Nine Constructors by Simon Peyton Jones discusses how all you need is System F (more or less).

u/hou32houin r/ProgrammingLanguages • Mentions

On “Treating functions as messenger nodes”

I’m going to add on more. Haskell’s purity allows extreme optimisation, which is not possible in other eager/imperative languages (i.e. most languages out there). This is possible because lazy evaluation and purity means that the order of evaluation doesn’t matter. Consequently, the compiler can perform optimisations such as term rewriting and etc. For reference, look at this lecture by Simon Peyton Jones. link to this video

u/bjzabaPikelet, Unnamed Binary DDLin r/ProgrammingLanguages • Mentions

On “Bootstrappable Builds”

Look at the richness of Haskell (which has generic types, exceptions, pattern matching, type bounds, etc) and see that this all can be elaborated into to the simplicity of GHC Core: ```haskell type CoreExpr = Expr Var data Expr b -- "b" for the type of binders, = Var Id | Lit Literal | App (Expr b) (Arg b) | Lam b (Expr b) | Let (Bind b) (Expr b) | Case (Expr b) b Type Alt b | Cast (Expr b) Coercion | Tick (Tickish Id) (Expr b) | Type Type type Arg b = Expr b type Alt b = (AltCon, b, Expr b) data AltCon = DataAlt DataCon | LitAlt Literal | DEFAULT data Bind b = NonRec b (Expr b) | Rec (b, (Expr b)) ``` Do check out this great presentation by Sim…

u/thmproverin r/ProgrammingLanguages • Mentions

On “Haskell-like language.”

Yeah, Into the Core - Squeezing Haskell into Nine Constructors by Simon Peyton Jones discusses how all you need is System F (more or less). It turns out that the desugared Haskell is "just" System F, and there are a number of ways to write an interpreter for this desugared version. Hinze's CAM paper explores a call-by-value variant, etc.

u/TizioCaio84in r/ProgrammingLanguages • Mentions

On “Optimization of pure functions by cases”

I think you may like this talk by Simon Peyton Jones. In particular, your idea looks to me like the 'case of case' transformation (which he describes) some inlining steps later. I know it's a bit long-winded, but in my opinion it's worth it.

u/Ok_Performance3280in r/ProgrammingLanguages • Mentions

On “Micro Haskell”

Hey OP. Have you seen SPJ's talk on the GHC IR? It's quite fascinating, and I bet you can use it in your project.