Finitio 0.4.x

Standard Library

Since 0.4, String, Integer, Date and the rest are not builtin. They are ordinary definitions living in a standard library, and a schema brings them into scope with an import:

@import finitio/data

{ name: String, age: Integer }

Without that first line, String is simply an unknown type and the schema fails to compile. This is the single biggest change for a reader coming from 0.3.

The library is written in Finitio itself, on top of builtin typesInteger is little more than a named alias for a host abstraction, which is precisely how Finitio stays host-independent at the schema level.

The portable core

These behave the same in both implementations and are what you should reach for:

TypeCapturesExchange representation
Nilthe null valuenull
Booleantrue and falsetrue / false
Trueonly truetrue
Falseonly falsefalse
Numericany number12, 12.0, 12.5
Stringany string"finitio"
Datea calendar date"2014-07-17"

The Any type is written . rather than named. Both implementations understand the dot; only finitio.js also defines Any as a name.

Numbers need care

Numeric behaves identically everywhere. Integer and Real do not, because the two host languages disagree about what 12.0 is.

documentInteger in RubyInteger in JSReal in RubyReal in JS
12acceptedacceptedrejectedrejected
12.0rejectedacceptedacceptedrejected
12.5rejectedrejectedacceptedaccepted

Ruby parses 12.0 from JSON into a Float, so it is a Real and not an Integer. JavaScript has a single number type in which 12.0 and 12 are the same value, so finitio.js decides by looking for a fractional part: 12.0 is an Integer and is not a Real.

In practice: Numeric is always safe; Integer agrees on values written without a decimal point; Real agrees on values that genuinely have a fractional part. A schema that must run under both bindings should avoid depending on how 12.0 is classified.

Dates and times

Date accepts an ISO 8601 date string in both, and dresses it into the host's date class — a Date in Ruby, a Date in JavaScript.

Beyond that the two libraries diverge:

Implementation-specific names

Some names exist in only one library. They are aliases for host abstractions, so they cannot be portable by nature:

Reading the library

The library is a normal Finitio file and worth a look — it is the clearest example of the language describing itself. In finitio-rb it lives at lib/finitio/stdlib/finitio/data.fio; in finitio.js at src/finitio/stdlib/data.fio. A definition looks like this:

Date = .Date <iso8601> .String \( s | Date.iso8601(s) )
                               \( d | d.iso8601       )

That is an abstract data type bound to the host's Date class through one named contract, iso8601, with its dress and undress functions. See information contracts for what those two functions mean.