Code Monkey home page Code Monkey logo

strictscript's Introduction

StrictScript

A toy compile-to-javascript language with a structural, fully inferred type system.

Some of the current features:

  • Structural typing with row polymorphism (see below).
  • Simple Lua-like syntax without deliminators or whitespace sensitivity.
  • Translates fairly directly to understandable JavaScript.

Immediate problems:

  • Implicit 'this'
  • Primitive types such as String are also objects.

To do (short-term):

  • Sum types
  • Zero overhead 'Maybe' type (using null)
  • Extensive source comments
  • Module system

Syntax

It's currently a mix of JavaScript and Lua. The JavaScript influence means it's familiar, but it has some nicities of the Lua language, including a lack of semicolons. The syntax is not whitespace significant.

Example:

var id = fn (x) { return x }

var sayHello = fn (name) {
  console.log("Hello " ++ name ++ ".")
}

sayHello("to you")

# Has type {name : String ...} -> ()
var sayHelloPoly = fn (thing) {
  console.log("Hello " ++ thing.name ++ ".")
}

sayHelloPoly({name: "to me", age: 20})
sayHelloPoly({name: "to me", nickname: "meh"})

The main differences from JavaScript here are the shortened 'function' keyword, a lack of semicolons, and the comment character (#).

Types

The type system is fully HM type-inferred.

See: Algorithm W Step-By-Step

Objects are constructed with curly braces and are structurally typed. This means functions can take any object that implements a required interface. The type system is row polymorphic, which takes care of the loss of information problem.

See: Objects and Aspects: Row Polymorphism

Object types are represented as {field1: type1, field2: type2 ...}. The ... means the type is polymorphic, i.e. {name: String ...} will accept the object {name: "Test", age: 20}.

strictscript's People

Contributors

kmahoney avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.