Skip to content
0:00 / 0:00

#hindley-milner#algorithmw#typeinference

f(by) 2019 - Christoph Hegemann, TYPE INFERENCE FROM SCRATCH

SPACE

5.6K subscribers • 3 videos on Hallway

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • Presented by Christoph Hegemann

Intermediate. Assumes working knowledge.

9.9K views7 years ago2 recommendations

Programming languagesComputer scienceLanguage design and type systemsCompilers and interpretersFunctional programming

Christoph Hegemann explains the fundamentals of the Hindley-Milner-Damas type system and implements Algorithm W in Haskell.

Static typing is experiencing a renaissance. Modern languages use type inference that lets you just write your expressions and have the compiler infer their types. But how does this work? I'll show you the fundamentals and theory by implementing a fully functional type checker/type inferencer. This talk will attempt to disenchant type systems/checker as something magic and show how they are normal (fun) programs. To do so it will present the Hindley-Milner-Damas type system which forms the basis for languages like OCaml, Haskell, PureScript, or Elm (and lots more). We'll implement Algorithm W, a type inference algorithm, for it in about a 100 lines of Haskell. Participants will leave with an understanding of typing judgements and terminology like substitution, instantiation, and unification.

Why it's here

2 people recommend this

What people say. Highly recommended as an easy-to-digest tutorial for implementing Hindley-Milner type inference from scratch.

Moments people linked to

u/Segeljaktusin r/ProgrammingLanguages • Recommends

On “Useful resources for writing a type checker”

I'd recommend you to take a quick look at: [video

u/superstar64in r/ProgrammingLanguages • Recommends

On “HM types and type schemes”

…rying has no effect on hindley milner. In fact, I'd wager most hindley milner tutorials assume single argument functions. If you want to add type annotations to hindley milner, you want rigid type variables. Unfortunately, I'm not familiar with any resources that teaches this. As for easy to digest hindley milner tutorials I'd recommend these: * link to this video * https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.65.7733&rep=rep1&type=pdf…

u/superstar64in r/ProgrammingLanguages • Recommends

On “Does anyone know of resources or languages which involve inferring types from function behavior?”

Are you sure you want you assigning to change the type of a variable? That seems like i'll open a can of worms to me. Anyway, if your not familiar with it yet, I recommend you learn about hindley milner type inference and bidirectional type inference. These are the most common ways(as far as I know) of doing type inference in functional languages. Here's some videos I recommend watching: * Hindley Milner: link to this video * Bidirectional: link to this video

u/superstar64in r/ProgrammingLanguages • Recommends

On “Considering language redesign, criticism requested”

Can I recommend, if you don't have it already, implementing Hindley Milner type inference. It's a fancy type inference algorithm that can infer the types of entire programs. The main limitations of it are: no implicit subtyping (if your language has inheritance you will need to explicitly super cast), no implicit conversions and callbacks can't be generic: ``def f(g): return (g(1),g(true)`` would be illegal. Apart from that, you entire program will be statically typed without any explicit types. Here's a video that gives an overview of how it's implemented: link to this video

u/superstar64in r/ProgrammingLanguages • Recommends

On “Writing a typechecker”

…ed to work on my pretty printing, I know) meaning these functions can take any type and return any type Apart from that, type inference is just regular hindley milner. Links: * My toy language: https://github.com/Superstar64/typi/ * Hindley Milner Tutorials: https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.65.7733&rep=rep1&type=pdf and link to this video…

u/Platzin r/haskell • Mentions

On “What is your favorite video with Haskell”

[Taming the C monster: Haskell FFI techniques - YOW! Lambda Jam 2018 | Fraiser Tweedale] Type Inference from Scratch - f(by) 2019 | Christoph Hegemann Deriving Via - SkillsCast| Andres Löh Beautiful folds are practical, too - MuniHac 2016 | Gabriel Gonzalez Honorable mention for comedic value: - Haskell in the Newsroom | Erik Hinton
8View on Reddit

u/gilmiin r/haskell • Mentions

On “Where to start learning about type checking?”

Christoph's talk is a good place to start.

u/superstar64in r/haskell • Mentions

On “Implementing new typesystems through a generic typesystem module”

This sounds like hindley milner but with sub typing. I recommend you look into implementing hindley milner and worry about sub typing later. Some resources I'd recommend: * Type Inference From Scratch(Quick talk on how it works) * Algorithm W Step by Step(Paper that showcases type inference code) * Unification Theory(The core algorithm behind hindley milner) After you get a good grasp of hindley milner, look into qualified types(typeclasses) to implement subtyping.