{"id":724,"date":"2013-01-22T12:08:30","date_gmt":"2013-01-22T17:08:30","guid":{"rendered":"http:\/\/alarmingdevelopment.org\/?p=724"},"modified":"2013-01-22T12:08:30","modified_gmt":"2013-01-22T17:08:30","slug":"down-the-rabbit-hole-of-types","status":"publish","type":"post","link":"https:\/\/alarmingdevelopment.org\/?p=724","title":{"rendered":"Down the rabbit hole of types"},"content":{"rendered":"<p><!--StartFragment--><\/p>\n<p>Time for a progress report, now that I have some progress to report. I didn&#8217;t get much research done last semester because I was teaching a new class:\u00a0<a href=\"https:\/\/stellar.mit.edu\/S\/course\/6\/fa12\/6.170\/courseMaterial\/topics\/topic1\/resource\/text\/text\">6.170 Software Studio<\/a>. It was a noble experiment with mixed results, but that is another story. Back in March I presented the latest version of Subtext at the\u00a0<a href=\"http:\/\/program-transformation.org\/WGLD\/WebHome\">IFIP Working Group 2.16 on Programming Language Design<\/a>. I realized then that Subtext should\u00a0be statically typed. Ever since I have been falling down the rabbit hole of types.<br \/>\n<!--more--><\/p>\n<p>Why static types? As I sheepishly admitted to my class, while my research is on dynamic languages I\u00a0prefer to program in static languages. I like the way types give guaranteed correct documentation as well as implicit assertion checking. I especially like the IDE support made possible by static types, such as the rename refactoring. Teaching in Ruby on Rails and JavaScript last semester has only reaffirmed these opinions.<\/p>\n<p>Perhaps the most compelling need for static types are in the UI and the DB, which ironically are considered extraneous by much of the PL community. It is commonplace to map a standard model object like a Customer into a corresponding screen form. Screen fields are in a sense statically typed: a field can accept a string, or maybe a number, or perhaps select from an enumeration, but you certainly can&#8217;t inject an arbitrary object pointer. Traditionally dynamic languages use templates to hard-code this type information into a UI language like HTML, spreading and coupling design information across different languages. A framework like Rails maintains its own internal type information from which it can generate screen forms and run an object-relational mapping. I conjecture that any sufficiently advanced dynamic language framework has its own ad hoc, informally specified, bug-ridden, slow implementation of a type system [with apologies to Greenspun]. DB schemas are really a form of static typing too, enforcing a rigid homogeneity needed for queries and indexing. Since UIs and DBs are naturally statically typed, it is natural that Subtext be also.<\/p>\n<p>I have\u00a0spent the last\u00a0nine months trying to work out an acceptable type system. People give me funny looks when I say that. After all, type theory is well understood, and most modern languages have converged on largely similar types. What&#8217;s the problem? The problem is that these systems are far too complex. What percentage of Java programmers fully understand its type system? I&#8217;m guessing 1%. I shudder to think what it is for Scala. I am not blaming type theorists &#8211; they are just the messenger &#8211; telling us that our language semantics are too complex to make sense of at compile time. I have considered and discarded maybe a dozen type systems because they were all just too damn complicated. I need something dead simple that will be clear to a novice programmer.<\/p>\n<p>It was only at the point of desperation that I could accept the solution: reject first-class functions. Specifically, function calls must statically resolve to a literal function. Subclasses are\u00a0limited to static hierarchies (no inner classes). There is no truly dynamic dispatch: all function and methods calls can in principle be inlined. This restriction bans dynamically created closures, often used\u00a0in callbacks. But a major goal of Subtext is to avoid the need for callbacks in the first place. Fancy closure tricks are\u00a0disallowed, but I want to discourage tricky programming anyway. Fortunately key functional idioms like mapping, folding, and comprehensions can still be provided by generics (aka templates).<\/p>\n<p>This design decision triggers a gratifying cascade of simplifications to the semantics and type system of the language. In fact the type system sublimes into what might better be called &#8220;static prototypes&#8221;. This feel right. It is also highly suggestive. My recent work has been about simplifying side-effects by restricting the ability to read and write through pointer variables. Now to simplify static types I am also restricting the ability to <em>jump<\/em> through pointers. The emerging moral is that <strong>pointers are the root of all semantic evil<\/strong>.<\/p>\n<p>Eliminating first-class functions is not a fashionable idea to say the least. Functional programming is all the rage in modern languages, as well as modern programming culture, not to mention its long dominance of PL theory. I too was a true believer. But I must follow where simplicity leads. What a long strange trip it&#8217;s been.<br \/>\n<!--EndFragment--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Time for a progress report, now that I have some progress to report. I didn&#8217;t get much research done last semester because I was teaching a new class:\u00a06.170 Software Studio. It was a noble experiment with mixed results, but that is another story. Back in March I presented the latest version of Subtext at the\u00a0IFIP &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/alarmingdevelopment.org\/?p=724\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Down the rabbit hole of types&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-724","post","type-post","status-publish","format-standard","hentry","category-general"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pfEnU-bG","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=\/wp\/v2\/posts\/724","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=724"}],"version-history":[{"count":13,"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=\/wp\/v2\/posts\/724\/revisions"}],"predecessor-version":[{"id":737,"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=\/wp\/v2\/posts\/724\/revisions\/737"}],"wp:attachment":[{"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alarmingdevelopment.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}