TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Hindley-Milner in Clojure

142 点作者 ericn超过 11 年前

10 条评论

exDM69超过 11 年前
Here&#x27;s the Hindley-Milner implementation (in Haskell) from a toy compiler project of mine. It was really enlightening to write it and surprisingly simple.<p><a href="https://github.com/rikusalminen/funfun/blob/master/FunFun/TypeChecker.hs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rikusalminen&#x2F;funfun&#x2F;blob&#x2F;master&#x2F;FunFun&#x2F;Ty...</a><p>This was also the first time I used monad transformers and almost the first non-IO monad application (I&#x27;ve used ST and Parsec before) I have dealt with. If you compare my code with the book source (Peter Hancock&#x27;s type checker in Peyton-Jones&#x27; &quot;Implementation of Functional Programming Languages&quot;, link in source code comment), my version using monads is a lot simpler to follow than the original, written in a pre-Haskell functional programming language called Miranda with no monads.<p>The type checker is a &quot;pure function&quot;, it has inputs and outputs but no side-effects but in the code you need to 1) generate unique &quot;names&quot; 2) bail out early on type errors. I solved this problem using Error and State monads. The Miranda code used an infinite list of numbers for unique names and cumbersome tricks to handle type errors.
评论 #7052321 未加载
评论 #7053793 未加载
willismichael超过 11 年前
I find it curious that the venn diagram seems to indicate that a sizable subset of people who are familiar with type theory don&#x27;t advocate either static typing or dynamic typing.
评论 #7051935 未加载
评论 #7054458 未加载
评论 #7052272 未加载
评论 #7052647 未加载
评论 #7052006 未加载
评论 #7051919 未加载
hardboiled超过 11 年前
Disagree about the idea that those who are unfamiliar with type theory prefer dynamic typing.<p>Typing preferences are usually due to trends in language usage having little to do with knowledge.<p>Plenty of java programmers use static typing without ever having to understand type theory.<p>But looking to history of language designers&#x2F;implementers<p>Dan Friedman<p>Gilad Bracha <a href="http://www.infoq.com/presentations/functional-pros-cons" rel="nofollow">http:&#x2F;&#x2F;www.infoq.com&#x2F;presentations&#x2F;functional-pros-cons</a><p>Guy Steele<p>Rich Hickey<p>All of these guys have worked on static languages, have a keener understanding of type theory than most, and yet they seem to promote dynamic languages at least when it comes to their pet languages.
评论 #7053441 未加载
评论 #7056557 未加载
评论 #7053412 未加载
评论 #7053390 未加载
nabla9超过 11 年前
Why not both?<p>ghc compiler in Haskell has -fdefer-type-errors flag. SBCL Common Lisp implementation has option to turn type warnings into errors. Extending -fdefer-type-errors function and creating better type checker for dynamic languages could achieve best of both worlds.
评论 #7052929 未加载
评论 #7052830 未加载
chongli超过 11 年前
Dynamic typing is just a special case of static typing where there is only one type!
评论 #7057020 未加载
评论 #7052335 未加载
评论 #7052530 未加载
评论 #7052592 未加载
__--__超过 11 年前
All this talk about formal type theory, but where are the references to the relevant studies? Where&#x27;s the data? The few studies[1][2][3][4] I&#x27;ve found are inconclusive one way or the other and none of them focus on error rates. I found another conversation about how to go about studying error rate in dynamically vs statically typed languages, but all I really found was this article studying the affect of hair style on language design[5].<p>[1] <a href="http://pleiad.dcc.uchile.cl/papers/2012/kleinschmagerAl-icpc2012.pdf" rel="nofollow">http:&#x2F;&#x2F;pleiad.dcc.uchile.cl&#x2F;papers&#x2F;2012&#x2F;kleinschmagerAl-icpc...</a> - maintainability<p>[2] <a href="http://dl.acm.org/citation.cfm?id=2047861&amp;CFID=399382397&amp;CFTOKEN=13654132" rel="nofollow">http:&#x2F;&#x2F;dl.acm.org&#x2F;citation.cfm?id=2047861&amp;CFID=399382397&amp;CFT...</a> - development time<p>[3] <a href="https://courses.cs.washington.edu/courses/cse590n/10au/hanenberg-oopsla2010.pdf" rel="nofollow">https:&#x2F;&#x2F;courses.cs.washington.edu&#x2F;courses&#x2F;cse590n&#x2F;10au&#x2F;hanen...</a> - development time, take 2<p>[4] <a href="http://pleiad.dcc.uchile.cl/papers/2012/mayerAl-oopsla2012.pdf" rel="nofollow">http:&#x2F;&#x2F;pleiad.dcc.uchile.cl&#x2F;papers&#x2F;2012&#x2F;mayerAl-oopsla2012.p...</a> - usability<p>[5] <a href="http://z.caudate.me/language-hair-and-popularity/" rel="nofollow">http:&#x2F;&#x2F;z.caudate.me&#x2F;language-hair-and-popularity&#x2F;</a>
评论 #7055920 未加载
评论 #7054973 未加载
kd0amg超过 11 年前
<i>I think you should implement Hindley-Milner in the language of your choice for a small toy λ-calculus.</i><p>Did this a little while ago (as a stepping stone to building an inference system for a more complicated calculus).<p><a href="https://gist.github.com/jrslepak/6158954" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;jrslepak&#x2F;6158954</a>
moomin超过 11 年前
As an aside, if you just want curried functions in Clojure, try poppea.<p><a href="https://github.com/JulianBirch/poppea" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;JulianBirch&#x2F;poppea</a>
评论 #7052565 未加载
michaelochurch超过 11 年前
I&#x27;m familiar with type theory and (often) a proponent of dynamic typing.<p>It depends on what you&#x27;re doing. If you&#x27;re building cathedrals-- high-quality, performance-critical software that can never fail-- then static typing is a great tool, because it can do things that are very hard to do with unit testing, and you only pay the costs once in compilation. There are plenty of use cases in which I&#x27;d want to be using a statically typed language like OCaml (or, possibly, Rust).<p>If you&#x27;re out in the bazaar-- say, building a web app that will have to contend with constant API changes and shifting needs, or building distributed systems designed to last decades without total failure (that may, like the Ship of Theseus, have all parts replaced) despite constant environmental change-- then dynamic typing often wins.<p>What I like about Clojure is that, being such a powerful language, you can get contracts and types and schemas but aren&#x27;t bound to them. I like static typing in many ways, but Scala left me asking the question, any time someone insists that static typing is necessary: <i>which</i> static type system?
评论 #7052834 未加载
评论 #7056568 未加载
评论 #7052749 未加载
elwell超过 11 年前
Douglas Crockford is a proponent of dynamic typing. (At least from what I read in the beginning of &quot;JavaScript: The Good Parts)
评论 #7053229 未加载