prose :: and :: conz

If I were writing a language

I’ve never honestly put thought into what I would want in my own language until recently. For years I wore blinders while working contently in the world of Java. However my shift to Scala and full-stack development over the last two years has exposed me to a little of the world outside. I doubt I’ll soon find time to dabble with language design. But if I did, here are the features, concerns, and priorities I’d pursue.


My language would be functional, of course. I don’t know that I would attempt the OO hybrid that Scala has going on. Polymorphism indeed has its problems and I don’t want to deal with those. Clojure’s ad-hoc polymorphism is very intriguing, and I just don’t feel that data needs to be hidden. Functional is where the future is, and frankly it’s how I like to code.

Static typing

Yeah, duh. If you follow me at all, you know how I feel on this topic. I’m curious if this makes the language more difficult to design and implement. It seems obvious that it would given that it’s one more responsibility of the language. On the other hand, perhaps those guarantees buys some nice properties further down the line. Regardless, I’d like my resulting language to have the fantastic properties afforded by static typing. Seeing it done well in Scala and taken to the next level in Haskell makes me believe it’s well worth the cost.

Compilation targets

If I’m gonna write a language (and I probably won’t) I would shoot the moon. There is no silver bullet in software, but I wouldn’t let that stop me from trying to write the language to rule them all. In my web-oriented mindset, this implies compilation to multiple targets so it can be used anywhere. First, I’d target the JVM. It is a very impressive piece of engineering and would open up many platforms. In particular, it would be viable as a backend language and as a mobile language on Android. The second compilation target would of course be JavaScript. I’m still not a huge proponent of JS compilation, but the idea of compiling to a limited and optimized subset of JS is attractive. Although JavaScript has it’s good parts, it is absolutely riddled with filth. Frankly, there is no getting away from it in our browser world. I would also be keen on compiling to some native, perhaps LLVM would suffice. Ultimately, I just want it to compile to something which can run on iOS. Then all of the bases would be covered.


In keeping with the previous section, my language would need to be web-ready to every extent possible. Compilation targets of the JVM, JavaScript, and LLVM are for web-readiness. The trickiest part will the the FFI, of course. I think I would prioritize great FFI with JavaScript/JSON. I know it runs against the static typing grain, but I really dig the simplicity of JavaScript objects. They’re all just a map. What I want is a way to be type safe, yet be able to utilize JavaScript objects with a native feel. I really don’t know how this would pan out. What I want to avoid is what we have in Scala, where we have case classes for our server-side data, then (assuming Lift) we have our JsonAST objects and the translations in between. What I imagine is something like all objects having a constructor which takes a JSON and instantiates the class. How do I reconcile that with static typing? No clue. Perhaps JSON-ready objects would be a special case of object. I’d have to play with it.

Also for FFI and interoperability, I would definitely make those calls safe. Scala’s interop with Java is super smooth and easy, but it leaves much to be desired by letting all of Java’s exceptions and nulls leak in. In my language, any calls to Java or JavaScript APIs would be wrapped in a monad like Lift’s Box which can be Empty (analogous to Scala’s None), Error, or Full[A] containing the result you hoped for (analogous to Scala’s Some).

Is Purescript close enough?

Perhaps so. I’ve been intrigued by Purescript lately, but have not committed any time to try it. It is strongly, statically typed and influenced by Haskell, so I know it’ll hit my first two items. It compiles to Javascript, and understand that the semantics are close to JavaScript. I’m optimistic that the FFI would be pretty good in that case. I’m not the first interested in a JVM compilation target either. I stay pretty busy in my free time as it is, and I’ve only made it worse by recently becoming a Lift committer and writing articles for NFJS Magazine. I’ve at least taken the first step and purchased PureScript by Example by Phil Freeman.

Those are a few quick things I would consider anyway. Most everything else about a language such as syntax and such isn’t that important to me. I just need these couple of things to build what I like building. What about you? What would you want in your own language? Or what languages do you think come close to what I already have in mind?

Leave a reply below, or send me a tweet.

Olde Comments
  1. Ian says:

    Just a few things that come to my mind:

    – Static/dynamic typing hybrid. Perhaps something like Scala’s Dynamic class combined with C#’s dynamic type, or perhaps a keyword, similar to val, var, def or lazy, that indicates a dynamically typed variable. Having some experience with advanced type programming in both static and dynamic languages, I certainly feel that they both can be extremely powerful as well as extremely dangerous if you’re not careful.

    – Pointers. This one is probably the most controversial, but in fact many concepts can be expressed most beautifully with pointers. Perhaps something like C#’s mandatory “unsafe” blocks to make sure that you don’t accidentally use pointer arithmetic in the wrong place.

    – Functional programming (duh), and probably OO features as well. I tend to think that encapsulation, in particular, is overrated among OO features (with the exception of things like the actor model). Of course, several experimental mixes of OO with functional programming exist, such as OCaml, Scala and modern C++, and I think it’s too soon to say which, if any, is “better.” While I’m on the subject of OO features, something like traits would also be mandatory for consideration in my ideal language.

    – Join patterns. Not a feature you usually find in languages, but I think my ideal language would define them, either in the base language or in the standard library. One thing I really like about these is that they mesh quite well with actors.

    – “Feels like” a scripting language. More of an aesthetic thing, really, but one of the things that really attracted me to Scala was how much it had the same feel as Python, which is the language I’m most familiar with. (I’ve since started using more functional techniques in Python!)

  2. […] is an outstanding question. I’ve long believed in the value of hijacking the JVM despite the impedance mismatches languages like Scala and Clojure encounter. But for most of the […]

Tagged with: scala (41), functional-programming (31), web-development (19), static-typing (16), liftweb (9), polyglot (7), javascript (6), clojure (5), haskell (3), purescript (3)