Language syntax

Status: the Rust compiler (rust/, cargo build --release -p sky) is the primary Sky compiler; the Haskell compiler is preserved under legacy-haskell-compiler/. Verified by the example sweep + compiler test suite (cargo test + xtask gates). See ../compiler/versions.md for the changelog.

Sky's surface syntax is Elm-compatible: most expressions that parse in Elm also parse in Sky. (See NOTICE.md for prior-art attribution; programming-language syntax is not itself copyrightable.)

A module

module Lib.Counter exposing (Counter, init, increment)

import Sky.Core.Prelude exposing (..)


type alias Counter =
    { value : Int
    , step : Int
    }


init : Counter
init =
    { value = 0, step = 1 }


increment : Counter -> Counter
increment c =
    { c | value = c.value + c.step }

Types

See types.md for the full type story.

Functions

-- Top-level function with annotation
add : Int -> Int -> Int
add x y =
    x + y

-- Anonymous function (lambda)
doubler =
    \x -> x * 2

-- Partial application
addFive =
    add 5

Let / in

area radius =
    let
        pi = 3.14159
        square x = x * x
    in
        pi * square radius

Case / of

describe n =
    case n of
        0 ->
            "zero"

        _ ->
            if n > 0 then
                "positive"
            else
                "negative"

Pattern matching is exhaustive — missing ADT variants or missing True/False in boolean matches are compile errors. See pattern-matching.md.

Pipelines

result =
    input
        |> String.trim
        |> String.toLower
        |> String.split ","
        |> List.map String.trim
        |> List.filter (not << String.isEmpty)

|> is left-to-right function application. <| is the reverse.

Record update

updated =
    { user | email = "new@example.com", age = user.age + 1 }

Multiline strings

html =
    """<div class="card">
    <h1>{{title}}</h1>
    <p>{{description}}</p>
</div>"""

Operators

OperatorMeaning
`> <|`
::Cons onto list
++Concatenate string / list
<< >>Function composition
+ - * / //Numeric — // is integer division
== /= < > <= >=Comparison
&& ||Boolean

No custom operators — language constraint.

Comments

-- line comment

{-
    block comment
    can span lines
-}

Reserved words

module, exposing, import, as, type, alias, if, then, else, case, of, let, in.

Non-reserved identifiers frequently used in Sky but which are not keywords: from, where.

Known limitations