How does the OCaml type inferencing algorithm work?

前端 未结 2 1507
南方客
南方客 2021-01-04 11:35

I\'m currently learning OCaml, and I\'m curious to HOW OCaml does its type inferencing. I know that it\'s done through a process called unification, and I tried reading abou

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-04 12:22

    The canonical reference for learning about HM type inference in ML would probably be Ben Pierce's "Types and Programming Languages." You can find the topic covered in chapter 22 of that book.

    The first instance of the type inference algorithm is known as Algorithm W.

    However, it may surprise you to know that -- in fact -- OCaml's implementation does not simply generate the constraints and solve them! In fact, it does a much more efficient graph based algorithm for type inference which (while speedy) leads to occasionally strange type errors being reported. You can look to references on explaining type errors in ML.

提交回复
热议问题