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.

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…