Skip to content
0:00 / 0:00

#haskell#ghc#ghccore

Vladislav Zavialov - Haskell to Core: Understanding Haskell Features Through Their Desugaring

Konfy

4K subscribers • 14 videos on Hallway

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • Presented by Vladislav Zavialov, GHC contributor

Advanced. Deep dive for people who know the field.

4.1K views6 years ago2 recommendations

Programming languagesSystems programmingHaskellCompilers and interpreters

Vladislav Zavialov explains how Haskell features are desugared into GHC Core, helping developers build a deeper mental model of the language.

Vladislav Zavialov Haskell programmer since 2012; GHC contributor since 2018. I’m interested in language design, programming language theory, and compiler engineering. Haskell to Core: Understanding Haskell Features Through Their Desugaring Haskell is an expressive language with many features. On one hand, it makes Haskell convenient, equipping the programmer with a rich arsenal of tools to get the job done and write high quality software. On the other hand, developing a thorough understanding of these tools, of all the language features, takes time, effort, and experience. One way to build an intuition for a language feature is to use it. Practice makes perfect, and by trial and error you can discover the ins and outs of using certain parts of the language. However, the knowledge acquired this way may be superficial, and the mental model will only be as good as it was needed for the tasks at hand. Deeper insight comes from a different perspective: you need to decompose a concept into its basic constituents. For example, what are multi-argument functions? In a curried language, we know that (a b c -˃ …) is much the same as (a -˃ b -˃ c -˃ …). Thus we have reduced the concept of a multi-argument function into a simpler concept of a single-argument function. For a more involved example: what is do-notation? To grasp it, you need to think how it is desugared into ˃˃= and ⋗⋗ (and also ˂*˃; with -XApplicativeDo). What about infix operators, if-then-else expressions, list comprehensions, type classes, type families, GADTs? How much Haskell is essential, and how much is sugar on top? In this talk, my first goal is to get you acquainted with GHC’s Core (System FC): a small, elegant language, into which every Haskell program is desugared during compilation; and my second goal is to demonstrate how the menagerie of Haskell features can be expressed using the few constructs of Core. In every-day programming, reading compiler-generated Core can be useful when you are investigating the performance of a particular piece of code. But more importantly, I hope that seeing how Haskell features are translated into Core can help you develop a deeper understanding of these features. haskell.love twitter.com/_haskellove

Why it's here

2 people recommend this

What people say. Recommended for understanding GHC Core and how Haskell's high-level features translate to a simpler intermediate representation.

u/Droneslutin r/haskell • Recommends

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/g__in r/haskell • Recommends

On “My take on haskell type classes”

…the user, so this cannot be implemented using only a fixed number of specialisations. It is true that type classes can be always translated away, but they won't always be specialized. In fact, most of the syntax can be translated away, and the entire Haskell on the value level can be squeezed to about 9 constructs (here are two talks about this: link to this video link to this video…