5-Minute Language Overview

What is it?

CKS is a language-neutral format for serializing data. It includes a text format (similar to XML, JSON, and YAML) and a binary format (like Protocol Buffers and Thrift). It has advantages over those other formats, and we’ll get to the reasons why, but let’s first look at the basics.

What do types look like?

Here’s an example:

def Person = {
  Name: String     // 'Name' is a string
  Age: Int         // 'Age' is an integer
  Sex: <           // either 'Male' or 'Female'
    Male
    Female
  >
  Hobbies: List(String)    // a list of strings
}

What do text values look like?

The standard text syntax for values is similar to JSON and YAML. Here is a value that matches the Person type defined above:

{
  Name = "Scooby Doo"
  Age = 36
  Sex = Male
  Hobbies = [
    "Ghosts"
    "Lunch"
  ]
}

Here’s an exactly equivalent value written a different way:

{
  Age = 36, Sex = Male
  Name = "Scooby Doo"
  Hobbies = ["Ghosts", "Lunch"]
}

Bigger Example

Some other features of CKS types:

Example type:

def Person = {
  Name: Name

  def Name = {
    First: String
    Middle: List(String)
    Last: String
  }

  Primary: ContactInfo
  Other: Map(String,ContactInfo)

  def ContactInfo = <
    // Each option has a different type of associated value.
    Email: String
    Icq: Int
    Cell: Phone
    def Phone = { AreaCode: String, Number: String }
  >

}

Example value:

{
  Name = {
    First = "Scooby"
    Middle = ["Herbert", "Walker"]
    Last = "Doo"
  }

  // Email is Scooby Doo's primary contact.
  Primary = Email: "sdoo@nasa.gov"

  // Scooby Doo has four other ways to be contacted.
  Other = [
    "Home"      -> Cell: { AreaCode = "510", Number = "555-1111" }
    "Mobile IM" -> Icq: 19482963015214928710304821
    "Work"      -> Cell: { AreaCode = "408", Number = "555-1111" }
    "Personal"  -> Email: "lonelydog15@yahoo.com"
  ]
}

Document-Style Data

The standard CKS value syntax works fine for “normal” data values, but doesn’t do so well with document-style text data. Take the following HTML fragment, for example:

<p>More info <a href="more/">here</a>.</p>

Represented in the standard CKS value syntax, it might look like:

p: {
  content = [
    text: "More info"
    a: {
      href="more/"
      content = [
        text: "here"
      ]
    }
    text: "."
  ]
}

Obviously, this isn’t convenient to read or write.

To deal with document-style data, CKS supports an alternative “markup” syntax that resembles HTML/XML. In fact, the HTML fragment above can be parsed as-is by a CKS value parser.

Internally, the same type system is used for both syntaxes, so they can be mixed:

{
  UserName = "lonelydog15"
  Email = "lonelydog15@yahoo.com"
  Signature = <p>More info <a href="more/">here</a>.</p>
}