TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Unification in Elixir

186 pointsby weatherlight11 months ago

3 comments

contificate11 months ago
It is worth noting that lots of applications of unification do not reify explicit substitutions in their implementations. You often see introductory type inference articles (usually focused on Hindley-Milner) use algorithm W, which uses a unification procedure that returns substitutions (which must then be composed with other substitutions). All of this is less efficient and arguably more error-prone and more complicated than the destructive unification implied by algorithm J (using the union-find data structure, often implemented invasively into the type representation to imply a union-find forest).<p>To this end, good coverage of decent (destructive) unification algorithms can be found in any simple resource on type inference (<a href="https:&#x2F;&#x2F;okmij.org&#x2F;ftp&#x2F;ML&#x2F;generalization&#x2F;sound_eager.ml" rel="nofollow">https:&#x2F;&#x2F;okmij.org&#x2F;ftp&#x2F;ML&#x2F;generalization&#x2F;sound_eager.ml</a>) or the Warren Abstract Machine (<a href="https:&#x2F;&#x2F;github.com&#x2F;a-yiorgos&#x2F;wambook&#x2F;blob&#x2F;master&#x2F;wambook.pdf">https:&#x2F;&#x2F;github.com&#x2F;a-yiorgos&#x2F;wambook&#x2F;blob&#x2F;master&#x2F;wambook.pdf</a>).<p>Of course, there are times where you would want to reify substitutions as a data structure to compose and apply, but most of the time you just want to immediately apply them in a pervasive way.<p>Despite what another comment says, unification is a valid - and rather convenient - way to implement pattern matching (as in the style of ML) in an interpreter: much like how you rewrite type variables with types you are unifying them with, you can rewrite the pattern variables to refer to the parts of the (evaluated) value you are matching against (which you then use to extend the environment with when evaluating the right hand side).
评论 #40844900 未加载
ReleaseCandidat11 months ago
While I&#x27;m at (free) books: a great example implementation of unification (in Lisp) is in chapter 11 &quot;Logic Programming&quot; of Peter Norvig&#x27;s &quot;Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp&quot;.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;norvig&#x2F;paip-lisp">https:&#x2F;&#x2F;github.com&#x2F;norvig&#x2F;paip-lisp</a><p>There is also an implementation in Python, but I have never tested it, just googled it now: <a href="https:&#x2F;&#x2F;github.com&#x2F;dhconnelly&#x2F;paip-python&#x2F;blob&#x2F;master&#x2F;prolog.py">https:&#x2F;&#x2F;github.com&#x2F;dhconnelly&#x2F;paip-python&#x2F;blob&#x2F;master&#x2F;prolog...</a><p><a href="https:&#x2F;&#x2F;dhconnelly.github.io&#x2F;paip-python&#x2F;docs&#x2F;prolog.html" rel="nofollow">https:&#x2F;&#x2F;dhconnelly.github.io&#x2F;paip-python&#x2F;docs&#x2F;prolog.html</a>
ReleaseCandidat11 months ago
Type checking (type inference) is the usual application of unification in programming languages (compilers or interpreters). Pattern matching does not need unification, because, as mentioned in the beginning of post, the &quot;matching&quot; is done one the left side only (no variables to &quot;match&quot; on the right side).
评论 #40843729 未加载