Join Newsletter

GHC Language Extensions

YOW! Lambda Jam 2019

Language extensions are everywhere in the modern Haskell world. As beginners we are often told by instructors or the compiler itself to enable particular extensions to allow for some syntactic sugar or enable a common feature. If we continue to use Haskell, we likely come to depend on even more language extensions, until it is common place for the first 10 lines of each file to be language pragmas. Many of us, myself included, are probably guilty of enabling extensions without fully understanding what they do, or understanding what tradeoffs and risks they might present. This talk hopes to improve the situation by shedding some light on commonly used extensions.

We'll start with what language extensions are and why they exist. Next we'll consider the different ways they may be enabled. From there, we'll look at some of the simpler extensions that provide syntactic sugar and not much else --- for example, LambdaCase and TupleSections. At this point we'll start to ramp up and look at some heavier weight extensions (e.g. ScopedTypeVariables and GeneralizedNewtypeDeriving), their use cases, and their tradeoffs. Finally, we'll take a more detailed look at some language extensions related to type classes. Specifically; FlexibleInstances, FlexibleContexts, MultiParamTypeClasses, and FunctionalDependencies will be covered.

There are over 100 language extensions supported by GHC 8.6, so it is not my intention to cover all or even most of them. Instead, I hope to explain and demystify some common language extensions and point out that they are not without risks.

Andrew McMiddlin

Functional Programming Engineer

Data61

Australia

I'm a functional programming engineer in the Queensland Functional Programming Lab at Data61. Earlier in my career I worked across a range of domains using conventional imperative programming languages, growing more and more frustrated with the difficulties of reasoning in a stateful and often untyped world. At some point I encountered Clojure and the ideas of immutability and referential transparency, which quickly changed the way I thought about solving problems. After being burned by the lack of a type system, I decided it was time to learn Haskell, and haven't looked back since.