Bosatsu Documentation
Bosatsu (菩薩) is the transliteration in Japanese of the sanskrit bodhisattva. A bodhisattva is someone who can reach enlightenment but decides not to, to help others achieve that goal. – Wikipedia
Bosatsu is a simple, non-turing complete language designed for configuration, queries and scripting. It borrows from Python, Haskell, Dhall and Rust.
Here is a working Bosatsu program to solve the first Project Euler problem:
package Euler/One
# see:
# https://projecteuler.net/problem=1
# Find the sum of all the multiples of 3 or 5 below 1000.
operator == = eq_Int
operator % = mod_Int
def operator ||(x, y):
True if x else y
def keep(i):
(i % 3 == 0) || (i % 5 == 0)
def sum(as): as.foldLeft(0, add)
# here is the pytthon version:
# >>> sum(i for i in xrange(1000) if keep_fn(i))
# 233168
#
# bosatsu version here
computed = sum([i for i in range(1000) if keep(i)])
test = Assertion(computed == 233168, "expected 233168")
Bosatsu is a new language with the following main features:
- a highly Python-inspired syntax including function definition, literal integers and strings, literal lists, list comprehensions, tuples and (string key) dictionaries. Generally, if a syntax is possible to support in the current type system with immutable values, we generally intend to support it.
- powerful pattern matching
- A static type system using a generalization of Hindley-Milner (or Damas-Milner) published in this paper by Simon Peyton Jones et. al.
- data classes or named tuples, which we call structs following Rust
- sum types, which we call enums following Rust.
- a package system with explicit import and export syntax.
There are also some un-features, or items we don’t currently and may never support
- There is very limited recursion. We only allow recursion which can never be used to make an infinite loop.
- Data structures can only be recursive in covariant positions (not the arguments of functions), and recursive functions have to be a certain form that will always terminate
- There is no
while
syntax. The closest we have are tail-recursive functions which recurse on sub-values of the inputs. There is a design sketch of automatically translating for loops on lists into folds issue 20.
The source code for this page can be found here.