Introduction

SAMLANG is a statically-typed functional programming language designed and implemented by Sam Zhou. The language is still under development so the syntax and semantics may be changed at any time.

The language can be compiled down to X86 assembly and machine code.

Getting Started

git clone https://github.com/SamChou19815/samlang # Clone repo
cd samlang
./scripts/release # Build the project

# Add samlang built project directory to path, or copy the files to another location.
PATH="$PATH:./build/release"
# Start using samlang
samlang
samlang -h
samlang compile

Program Layout

Here is an example program:

class HelloWorld(val message: string) {
  private method getMessage(): string = {
    val { message } = this;
    message
  }

  function getGlobalMessage(): string = {
    val hw = { message: "Hello World" };
    hw.getMessage()
  }
}

class Main {
  function main(): string = HelloWorld.getGlobalMessage()
}

A module contains a list of classes, and a class can either be a normal class or utility class, which will be explained later. If there is a module named Main and the module contains a no-arg function main, then the entire program will be evaluated to the evaluation result of the function call Main.main(). If there is no such module, then the evaluation result will be unit.

Each .sam source file defines a module. You can use a different module's classes by import

import { ClassA, ClassB } from Foo.Bar.Module
import { ClassC, ClassD } from Baz.Foo.Module

class ClassD {
  function main(): int = ClassA.value() + ClassC.value()
}

Cyclic dependencies and mutual recursion between different classes are allowed. However, cyclic dependencies between modules are strongly discouraged.