Languages

Samek

The back-end language: gateways, stateless actors, repositories read by specifications and policies on the bus, compiled into microservices.

In use by every MLambda service and app

Samek

Samek (ס) is MLambda’s back-end language. A service is written as gateways, stateless actors on MLambda.Actors, repositories on MLambda.Data and policies on the bus, with recursion and pattern matching. The compiler writes Aleph, and every check it makes is a Shin law.

An actor

import Limits

@public @route("account/{id}")
@passivate(5m)
@supervision(oneForOne { Timeout => Restart, _ => Escalate })
actor AccountActor(repository: AccountRepository, entries: EntryRepository): Actor {

    fn receive(id: String, message: Command): Reply => repository.one(AccountById(id)) >>= match {
        Nothing                                        => unopened(id, message)
        Just(account: Account(status: Active))         => active(account, message)
        Just(account: Account(status: Frozen(reason))) => frozen(account, message, reason)
    }

    // the laws decide whether the limits allow it; the actor matches what they say
    fn permitted(account: Account, w: Withdraw): Reply => match Limits.refuses(account.limits, w, home: homeCountry) {
        []      => withdraw(account, w.tx, w.amount)
        reasons => fail(NotAllowed(join(", ", reasons)))
    }
}

The actor holds nothing. Every message reads the account through its repository, the laws of Limits.hs decide what the limits allow, and what it writes is committed in one batch when it returns.

What a service is made of

  • Commands and queries. A command is taken by receive, one message at a time. A query is answered by read, which never writes. A query actor is @ephemeral and answers many queries at once.
  • Repositories and specifications. Data is read by specifications, not by hand-written queries, so a read can be checked and paged.
  • Policies on the bus. What an event sets off elsewhere is a policy, never a call to another service.
  • Doors. A .sk file reaches a Shin theory (import Limits opens Limits.hs), a Hilbert maths file (run on Tensor) or an Aleph module, each called like an object.
  • Gateways. An edge publishes its routes, OpenAPI, GraphQL, a proxy, measures and a /docs page. The Gateway Console (an Aphrodite window) explores them.
  • Telemetry for free. The generated code reports spans, lines and counts to Helios.

From code to deployment

samek build compiles every artifact of a system and writes deploy/artifacts.toml: what was built and everything it needs to run. Samek knows nothing about infrastructure. Arkhos reads that file and deploys.

Every app of the family (CRM, ERP, Desk, Make, Factory, Transport, SCM, WMS, Last Mile, Shop, Box, Muse) and every service (OAuth, Mail, Store, Iris, Helios, Neuron) is written in Samek.