Ceylon (programming language)

From Wikipedia, the free encyclopedia
Jump to: navigation, search
Ceylon (programming language) logo.png
Paradigm Object-oriented
Designed by Gavin King, Red Hat
First appeared 2011
Stable release 1.2.0[1] / October 29, 2015; 28 days ago (2015-10-29)
Typing discipline Static, strong, safe
License Apache v2
Filename extensions .ceylon
Website ceylon-lang.org
Influenced by
Java, Scala, Smalltalk

Ceylon is an object-oriented, strongly statically typed programming language with an emphasis on immutability, created by Red Hat. It is based on the Java programming language. Ceylon programs run on the Java Virtual Machine, and can be compiled to JavaScript.[2][3]

Ceylon aims at solving the following problems its developers experienced with Java:[4][5][6]

  1. improved structured data and user interfaces
  2. language level modularity
  3. support for first-class and higher-order functions
  4. do away with clumsy metaprogramming

The name "Ceylon" is an oblique reference to Java, in that Java and Sri Lanka, formerly known as Ceylon, are islands known for growth and export of coffee and tea.

Language features[edit]

Ceylon is heavily-influenced by Java's syntax, but adds many new features.

Type System[edit]

One of the most novel aspects of Ceylon is its type system. Ceylon foregoes java's primitive types[7] and boxing in favor of a type system composed entirely of first-class objects.

More uniquely, Ceylon allows for union and intersection types, where a variable can have more than one type. For example, here is a Ceylon function which may take either an integer or a string:

shared void integerOrString(Integer|String input) {
    if (is Integer input) {
        print("Got the integer ``input``");
    } else {
        print("Got the string '``input``'");

An important component of this feature is flow-based typing. For example, the following code is invalid:

shared void integerOrString(Integer|String input) {
    Integer added = input + 6; // Illegal, we don't know that input is definitely an integer.

    if (is Integer input) {
        Integer added = input + 6; // This is fine. input can only be an integer here.
        print("Got the integer ``input``");
    } else {
        print("Got the string '``input``'");

The first example is wrong because the + operator is not defined for Integer|String, only for Integer, but, within the if block, we have checked the type of input and know it to be simply an Integer, so Ceylon narrows the type of the variable input and we can treat it like an integer.

Type Inference[edit]

Ceylon is strongly and statically typed, but also has support for type inference. For example, in most strong, statically typed languages, one would create an Integer variable with value 3 like so:

Integer foo = 3;

This is perfectly valid in Ceylon, however Ceylon also allows the following:

value foo = 3;

Here, the value keyword indicates we are declaring a variable, but does not state its type. Instead, the type is inferred to be Integer from our initial value of 3.


All the work, including the website, the language specification, and Ceylon Herd, is freely available under open source licenses.[8]

See also[edit]


  1. ^ King, Gavin. "Ceylon 1.2.0 is now available". Retrieved 29 October 2015. 
  2. ^ "Ceylon 1.0 beta". Retrieved 2013-09-26. 
  3. ^ "Project Ceylon – Red Hat builds Java replacement". The Register. 2011-04-13. Retrieved 2011-11-27. 
  4. ^ Introducing the Ceylon Project – Gavin King presentations at QCon Beijing 2011
  5. ^ Gavin King (2011-04-13). "Ceylon". Retrieved 2011-11-27. 
  6. ^ "Ceylon JVM Language". infoq.com. 2011-04-13. Retrieved 2011-11-27. First, I never billed this as a Java Killer or the next generation of the Java language. Not my words. Ceylon isn't Java, it's a new language that's deeply influenced by Java, designed by people who are unapologetic fans of Java. Java's not dying anytime soon, so nothing's killing it 
  7. ^ King, Gavin. "Ceylon: Language Design FAQ". 
  8. ^ licences, official website

External links[edit]