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 • 48 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.

Moments people linked to

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/Droneslutin r/haskell • Mentions

On “Is core the level below Haskell that we should understand?”

You definitely do not *need* to understand Core in order to use Haskell efficiently, but at the same time it wouldn't hurt and in some cases it could definitely help. I think that what understanding 'one level lower' really means is having the ability to reason about things like memory allocation, what the stack and heap look like when things are running, and that's exactly what you get when you think about the assembly when writing C and the JVM when writing Java. Understanding Core, and STG, will definitely help understand what is going on in those areas when writing Haskell. There are two really good talks about Core by SPJ and Vladislav Zavialov; Csaba Hruska gave a talk recently…

u/phischuin r/haskell • Mentions

On “Trying to understand compiler.”

I think this recent talk by Simon Peyton Jones is exactly what you are looking for: Into the Core.

u/SolaTotaScripturain r/haskell • Mentions

On “Why does people say haskell is mathy?”

Like in mathematics, it's based on functions and declarations. You say what a value "is" rather than mutating variables. This is why Haskell is called "declarative". For example: fib 0 = 0 fib 1 = 1 fib n = fib (n - 1) + fib (n - 2) It also heavily relies on higher order functions and recursion. This is a more naturally mathematical approach to solving problems, and is often cumbersome in imperative languages. It also just implements a lot mathematics. For example, a lot of the typeclasses in the standard library are straight from an algebra textbook: semigroups, monoids, functors, monads etc. Purity is also important. Imperative functions don't really make sense *mathematica…

u/alan_zimmin r/haskell • Mentions

On “Looks like "join points" come to GHC (nice wins)”

I am pretty sure SPJ explains it here: link to this video

u/Iceland_jackin r/haskell • Mentions

On “Looks like "join points" come to GHC (nice wins)”

Link.
8View on Reddit

u/metamlin r/haskell • Mentions

On “Best way to get familiar with Core?”

You may want to start with these slides and talk: http://www.erlang-factory.com/static/upload/media/1488806820775921euc2016intothecoresimonpeytonjones.pdf and link to this video As well as this for references: https://xnning.github.io/papers/ghc-core-review.pdf

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/Iceland_jackin r/haskell • Mentions

Lambda calculus is good as the simplest treatment of variables and binders. Having a vocabulary like alpha-equivalence to capture the intuition that `\x -> x` and `\y -> y` are the same function. Knowing that `(\f a -> f a) a` can't naively reduce to `\a -> a a`. Understanding that datatypes don't add expressive power since they can be modelled as functions. ghc uses a (higher-order polymorphic) lambda calculus (with coercions) as its internal Core language (Into the Core - Squeezing Haskell into Nine Constructors by Simon Peyton Jones) which has practical implications when you start studying Haskell, and it's good to have an idea of the basics. A lot of Haskell features will use the lambd…

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/lightyagami11in r/haskell • Mentions

On “Newbie Question -- What is Haskell Core?”

link to this video

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/Noughtmarein r/haskell • Mentions

On “Monthly Hask Anything (October 2020)”

Maybe `abs_` should be specialized before that rule can be applied? Try specializing it manually, change the type signature to `abs_ :: forall s. MTensor s -> ST s (MTensor s)`. The `@ (ST s_a4gx)` is a type application and `($fPrimMonadST0 @ s_a4gx)` is passing the type class dictionary of the `ST s` instance of the `PrimMonad` class. The lambda is there to bind the `s` type variable in System-F style. SPJ has a nice introduction to core: link to this video He talks about the System-F style type variable binding around 13:00.