Ceylon (programming language)

Ceylon was an object-oriented, strongly statically typed programming language with an emphasis on immutability, created by Red Hat. Ceylon programs run on the Java virtual machine (JVM), and could be compiled to JavaScript. The language design focuses on source code readability, predictability, toolability, modularity, and metaprogrammability.

Important features of Ceylon include:
 * A type system enforcing null safety and list element existence at compile time
 * Regular syntax and semantics, avoiding special cases and primitively-defined constructs in favor of syntactic sugar
 * Support for generic programming and metaprogramming, with reified generics
 * Modularity built into the language, based on JBoss modules, interoperable with OSGi and Maven
 * powerful tools, including an Eclipse-based IDE

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.

In August 2017, Ceylon was donated to the Eclipse Foundation. Development slowed down and finally stopped in 2020. In April 2023, Eclipse Foundation declared the termination of the transition.

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

Type system
One of the most novel aspects of Ceylon compared to Java is its type system. Ceylon foregoes Java's primitive types and boxing in favor of a type system composed entirely of first-class objects. While this may cause boxing overhead in some situations, it makes the type system more uniform.

Ceylon allows for union and intersection types, in a similar fashion to TypeScript, Whiley and Flow, which in fact, took the idea from Ceylon.

Union types, written, allow a variable to have more than one type. The following example shows a Ceylon function which may take either an integer or a string:

Intersection types, written, are the theoretical foundation of flow-sensitive typing:

The condition  narrows the type of   to  , which distributes to , which, as  and   are disjoint types, is equivalent to   (  is the empty bottom type), which simplifies to just.

Null safety
Union and intersection types are used to provide null safety. The top type of the Ceylon type hierarchy is the class , which has two subclasses:, the superclass of all normal classes and all interfaces, and  , with the only instance. Since  and   are disjoint types, most regular types like   or   are not nullable; a nullable type is the union, abbreviated.

Intersection types can be used to get a non-optional type out of a possibly-optional type, such as a type parameter. For example, the signature of a function that removes  elements from a stream of values could be:

When  is called with a stream of   elements, the result will be a stream of   elements, which simplifies to.

Functions
Similarly to many modern languages, Ceylon supports first class functions and higher order functions, including function types and anonymous functions

Enumerated types
Similar to Java and many other languages, and with a similar mechanism as algebraic types, Ceylon supports enumerated types, otherwise known as enums. This is implemented in Ceylon with a pattern of limiting the instances of an abstract class at declaration to a limited set of objects (in this case, singleton instances). Another way to implement this pattern is with the new constructor feature in Ceylon 1.2 where the objects are implemented as different named constructor declarations.

Type inference
Ceylon is strongly and statically typed, but also has support for type inference. The  keyword is used to infer the type of a variable, and the  keyword is used to infer the type of a function. The following two definition pairs are each equivalent:

However, to make single-pass type inference possible, type inference is only allowed for non-toplevel and unshared declarations.

Entry point with names
By default the starter runs the shared run function of a module: but any other shared function without parameters can be used as main calling the program with the run parameter, like this:

Versions
Versions of Ceylon released:


 * M1 0.1 "Newton" (Dec 20 2011)
 * M2 0.2 "Minitel" (Mar 2 2012)
 * M3 0.3 "V2000" (Jun 21 2012)
 * M3.1 0.3.1 "V2000" (Jul 6 2012)
 * M4 0.4 "Analytical Engine" (Oct 29 2012)
 * M5 0.5 "Nesa Pong" (Mar 13 2013)
 * M6 0.6 "Virtual Boy" (Sep 23 2013)
 * 1.0 beta "Virtual Boy" (Sep 24 2013)
 * 1.0.0 "No More Mr Nice Guy" (Nov 13 2013)
 * 1.1.0 "Ultimate Ship The Second" (Oct 09 2014)
 * 1.2.0 "A Series of Unlikely Explanations" (Oct 28 2015)
 * 1.2.1 "Irregular Apocalypse" (Feb 11 2016)
 * 1.2.2 "Charming But Irrational" (Mar 11 2016)
 * 1.3.0 "Total Internal Reflection" (Sep 19 2016)
 * 1.3.1 "Now We Try It My Way" (Nov 22 2016)
 * 1.3.2 "Smile Tolerantly" (Mar 02 2017)
 * 1.3.3 "Contents May Differ" (Aug 21 2017)

License
All parts of Ceylon are available as free software, mostly the Apache License. Part of the source code is licensed under LGPL.