7 ms·
Hindley-Milner in Clojure
- willismichael 13y agoI find it curious that the venn diagram seems to indicate that a sizable subset of people who are familiar with type theory don't advocate either static typing or dynamic typing.
- zephjc 13y agoI think that was the joke :)
- kleiba 13y agoI think the joke is rather the small overlap between people who advocate dynamic typing and people who know type theory.
- tokipin 13y agowhich doesn't mean much. it could be that people who would be interested in learning type theory in the first place would prefer static typing regardless, with a similar argument for the case of dynamic typing
- Tuna-Fish 13y agoThat's not relevant to the original point, which was that the fact that dynamic typing enthusiasts not knowing type theory makes debate on the subject not interesting. Case in point: just look at https://news.ycombinator.com/item?id=7054960 https://news.ycombinator.com/item?id=7054960 , where someone who apparently likes dynamic types lists a ton of studies done by other people who like dynamic types where modern dynamically typed languages are tested against the best static types that the early 60's have to offer. The only part I'd change about that diagram is move the "knows type theory" area way down, so that the majority of static typing enthusiasts are not covered either (but so that the proportion of static typing enthusiasts that are covered is much greater than the proportion of dynamic typing enthusiasts who are covered.) It's depressing to talk about types when living in a world where both sides of the fence consists mostly of people who think static typing means Java, and where new, "exciting" statically typed languages like Go can have a type system that completely ignores all development that has happened in the past 50 years. Modern static types are actually good, actually useful, and only ever bother you when not bothering you would mean that your code can crash at excecution time.
- tokipin 13y agonot necessarily a response to your comment, but i think you underestimate just how much the static/dynamic preference rests on fundamental psychology. for example, generally speaking i only use basic data structures (lists or hash tables), so introducing types would be over-engineering (note, i'm familiar with e.g. Haskell's type system). for me the idea of typing implies a programming style complicated enough to require it. it's only at a larger architectural scale that i think typing pays off that said, C# is still my favorite production language.
- aidenn0 13y agoI would suspect that a large fraction of them are mathematicians and not particularly interested in how people program.
- octo_t 13y agoI love type theory, but I think a language like Sage[1] is probably the most interesting way forward. [1] - http://sage.soe.ucsc.edu/ http://sage.soe.ucsc.edu/
- StefanKarpinski 13y agoThat's a somewhat unfortunate name to choose for a new language given the existence of this well-established system: http://www.sagemath.org/ http://www.sagemath.org/
- sfvisser 13y agoWhy the 'but'? There seems to be quite some type theory involved in Sage.
- ufo 13y agoI really like the idea behind Sage but I found it kind of funny that in their test cases all the ".out" files are empty because none of the programs actually do any IO. No hello-world for you :P
- tel 13y agoHow do you feel about dependently typed systems?
- brudgers 13y agoCS departments are where people exposed to Type Theory tend to be exposed to it. The sorts of languages that tend to be taken seriously in such departments [yes, I know there are exceptions] tend to be statically typed. Java and C++ just have more gravitas than Ruby and JavaScript and Lisps are for hippies.
- TeeWEE 13y agoI'm familiar with type theorie but i'm not a proponent of either of them. Sometimes its better to use static typing and sometimes its better to use dynamic typing. Howeover most of the times I would prefer static typing. I think in this subset you're mentioning?
- technomancy 13y agoI wouldn't say I'm intimately familiar with type theory, but I'm certainly old slash grumpy enough to not be an "advocate" of anything except learning both and thinking for yourself about the problem at hand.
- exDM69 13y agoHere's the Hindley-Milner implementation (in Haskell) from a toy compiler project of mine. It was really enlightening to write it and surprisingly simple. https://github.com/rikusalminen/funfun/blob/master/FunFun/TypeChecker.hs https://github.com/rikusalminen/funfun/blob/master/FunFun/Ty... This was also the first time I used monad transformers and almost the first non-IO monad application (I've used ST and Parsec before) I have dealt with. If you compare my code with the book source (Peter Hancock's type checker in Peyton-Jones' "Implementation of Functional Programming Languages", 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. The type checker is a "pure function", it has inputs and outputs but no side-effects but in the code you need to 1) generate unique "names" 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.
- moomin 13y agoAs an aside, if you just want curried functions in Clojure, try poppea. https://github.com/JulianBirch/poppea https://github.com/JulianBirch/poppea
- derengel 13y agoNoob question, doesn't partial provides curried functions?
- brandonbloom 13y agoPartial application and curried functions are subtly different. Consider a "+" operator that does currying: ((+ 5) 10) If the plus operator is not currying, that's either an arity or type error. You're either not supplying enough arguments to +, or you're trying to do this: (5 10) Partial application can be explicit, without currying: ((partial + 5) 10)
- lmkg 13y agoA 'true' curried function in clojure doesn't need partial because it overloads on the arity of the function. It automatically partializes itself if it's called with too few arguments. E.g. you have a function f that takes two arguments, x and y. If the function is truly curried, then (f x y) is a full function call of f that returns a value, while (f x) returns a function of one argument, as if you had used partial. You could create a (two-argument) currying helper-function with the following: (defn curry-2 [f] (fn ([x] (partial f x)) ([x y] (f x y)))) Basically with a currying function, (f x y) and ((f x) y) are equivalent calls, without the need for partial. The reason this isn't more pervasive is because it doesn't play well with optional parameters, &rest parameters, arity overloading, or other ways in which the number of arguments to a function might vary (Haskell permits currying by not allowing variable param lists). Clojure has a couple of library functions that use this pattern (notably, the reducer library), but it's not ubiquitous.
- moomin 13y agoIndeed, that's exactly what poppea does. The code is a generalisation of the code in the reducers library.
- chongli 13y agoDynamic typing is just a special case of static typing where there is only one type!
- sfvisser 13y agoEven when this is true, this special case of static typing gives you exactly none of the advantages of general static typing.
- chongli 13y agoYes, of course. I'm a big proponent of static typing, or (as Bob Harper likes to call it) typing! This is in contrast with unityped languages.
- bcoates 13y agoAn idealized dynamic strong typed language can actually give you the guarantee that all statically valid programs give you well-defined runtime behavior. This is a huge advantage over weakly typed languages that you also get out of the idealized static typed language. The issue is, outside of languages with very baroque type systems or monstrosities like Java's sandbox, static typing often winds up decaying into weak typing, which offer much weaker behavior guarantees than real-world dynamic languages.
- dmytrish 13y agoThat's not quite true: there are many types, but the type checking is delayed into run time. Though your point of view may be also correct with respect to definitions (if you assume that types exist only during compile time).
- chongli 13y agoThat's not quite true: there are many types, but the type checking is delayed into run time. Runtime checks are not type checks[0], they are class checks. [0]. https://existentialtype.wordpress.com/?s=dynamic+typing https://existentialtype.wordpress.com/?s=dynamic+typing
- nabla9 13y agoWhy not both? 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.
- emiljbs 13y agoI agree. Good dynamic languages (Common Lisp, Smalltalk, Factor) has a lot going for them but static typing is also really nice. A mix between the two (preferably something that starts out as a dynamic lang and slowly moves towards being static) would be great (Common Lisp kinda does this with optional static typing).
- aidenn0 13y agoCL's type system has a few warts to really do static typing well. For a language that truly hass optional static types see Shen[1] [1] http://shenlanguage.org/ http://shenlanguage.org/
- ufo 13y agoThe actual reason for why not both is that its actually very hard to do and is still kind of an open problem. Some things are easy to do statically but hard to check dynamically (for example, parametric polymorphism or type-based overloading and name resolution) and some things are easy to check dynamically but hard to specify using static types (for example, array bounds checking).
- nabla9 13y agoYou can do those things that are easy to do statically at development/testing time and those thing that are easy to do dynamically in runtime. Some things like overloading based on return values don't work dynamically, but you could either choose to not have them or resolve them in development time. I would like to see languages where dynamic vs. static is continuum and programmers can determine how much they need want case by case basis.
- michaelochurch 13y agoI'm familiar with type theory and (often) a proponent of dynamic typing. It depends on what you're doing. If you'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'd want to be using a statically typed language like OCaml (or, possibly, Rust). If you'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. What I like about Clojure is that, being such a powerful language, you can get contracts and types and schemas but aren'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: which static type system?
- augustl 13y agoInteresting insights. Would love to read more aobut this. Usually the arguments are "I'm a bad programmer like everyone else so I need verification" or "the world is dynamic".
- runT1ME 13y agoThe good arguments for static typing are much different than "I'm a bad programmer". Google "Theorems for free". One of the most life-altering CS papers I've read. :-)
- hesselink 13y agoI've heard this argument a lot, and I disagree. If your software is changing a lot, that is where types really shine. Refactoring is a breeze when you have types: you just change the code you want to improve, and all use sites are pointed to by the compiler. This is taken from daily experience: I work on a code base that is about 25K lines of Haskell and 35K lines of Javascript. Refactoring the Haskell is a pleasure. Refactoring the Javascript is something we dread, and always introduces bugs, some of which might linger for up to a year.
- elwell 13y agoDouglas Crockford is a proponent of dynamic typing. (At least from what I read in the beginning of "JavaScript: The Good Parts)
- Semiapies 13y agoWhat's the relevance of that point? He doesn't appear to be mentioned in the post.
- kd0amg 13y agoI think you should implement Hindley-Milner in the language of your choice for a small toy λ-calculus. Did this a little while ago (as a stepping stone to building an inference system for a more complicated calculus). https://gist.github.com/jrslepak/6158954 https://gist.github.com/jrslepak/6158954
- hardboiled 13y agoDisagree about the idea that those who are unfamiliar with type theory prefer dynamic typing. Typing preferences are usually due to trends in language usage having little to do with knowledge. Plenty of java programmers use static typing without ever having to understand type theory. But looking to history of language designers/implementers Dan Friedman Gilad Bracha http://www.infoq.com/presentations/functional-pros-cons http://www.infoq.com/presentations/functional-pros-cons Guy Steele Rich Hickey 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.
- rtfeldman 13y agoThe most useful takeaway from that graph is the insight into how many type theory aficionados look at the world.
- kd0amg 13y agoFWIW, I don't think the diagram is claiming that people who are unfamiliar with type theory tend to prefer dynamic typing, rather that people who prefer dynamic typing tend to be unfamiliar with type theory.
- the_af 13y agoI'm not disagreeing with you (that a lot of people go with what's trendy or what they already know), but I wouldn't put Gilad Bracha in the list of knowledgeable people. I've seen the talk you are linking to and it's not very impressive... he sounds mostly whiny to me. In his own blog, when he writes about about functional programming or type theory, he gets called out by the people who really know about it.
- codygman 13y agoI would agree, I don't see why Gilad Bracha is on that list.
- coolsunglasses 13y agoGilad Bracha has no idea what the hell he's talking about. Rich hasn't worked on static languages and I'm not familiar with him having done anything in type theory. He wanted a nicer, practical Lisp first and foremost. A helpful compiler wasn't high on his list of priorities. Guy Steele's most recent work has involved functional, statically typed programming languages: http://en.wikipedia.org/wiki/Fortress_(programming_language) http://en.wikipedia.org/wiki/Fortress_(programming_language) One of Friedman's most recent books http://www.ccs.neu.edu/home/matthias/BTML/ http://www.ccs.neu.edu/home/matthias/BTML/ was on ML which is a statically typed, functional programming language. The smart people that weren't using static types back in the 70s and 80s weren't using them because the statically typed languages available back then were fuckin' awful except for ML and Miranda. We can do a lot better as programmers these days. Stop giving yourself an excuse to not learn new things.
- __--__ 13y agoAll this talk about formal type theory, but where are the references to the relevant studies? Where's the data? The few studies[1][2][3][4] I'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]. [1] http://pleiad.dcc.uchile.cl/papers/2012/kleinschmagerAl-icpc2012.pdf http://pleiad.dcc.uchile.cl/papers/2012/kleinschmagerAl-icpc... - maintainability [2] http://dl.acm.org/citation.cfm?id=2047861&CFID=399382397&CFTOKEN=13654132 http://dl.acm.org/citation.cfm?id=2047861&CFID=399382397&CFT... - development time [3] https://courses.cs.washington.edu/courses/cse590n/10au/hanenberg-oopsla2010.pdf https://courses.cs.washington.edu/courses/cse590n/10au/hanen... - development time, take 2 [4] http://pleiad.dcc.uchile.cl/papers/2012/mayerAl-oopsla2012.pdf http://pleiad.dcc.uchile.cl/papers/2012/mayerAl-oopsla2012.p... - usability [5] http://z.caudate.me/language-hair-and-popularity/ http://z.caudate.me/language-hair-and-popularity/
- jgg 13y agoAre you trolling? I seriously can't tell...
- exDM69 13y agoI glanced over the studies you linked to and in all of them, the languages used as examples of static typing are Java, C and C++. There's no mention of type inference or any languages that have a more advanced static typing scheme like ML or Haskell. A lot of it seemed to be a "Java vs. Ruby fight" with a slight bias towards the latter in the authors. To joke and exaggerate a little, those studies seem to be done by people who belong to the "proponents of dynamic typing" and not "familiar with type theory" bin of people in the Venn diagram in the OP.
- __--__ 13y agoI agree completely, that's why I used the word "inconclusive." Still, it's the only real data we have on static vs dynamic typing. Until we get better data, everything is just opinion and preference. Well informed opinions, in the case of those familiar with type theory (which I am not), but opinion nonetheless.