2026-11-14
Statically Typed Array Programming Language Experiment (STAPLE) is a programming language I've begun to work on recently. I have decided to write it in Haskell because it allowed me to write code and iterate quickly, making design the slowest part of the process.
STAPLE has three main types: An array where , scalar types , and function types . The type parameter of an array can only either be an array or a scalar type. (as it is currently not possible to support functions) An array can either have a known fixed axis (length of array) or an unknown axis.
The function type takes in any type and returns a type depending on the input type. Since the type system cannot properly represent what types a function will accept and return, we will denote it as of since we don't know what type will actually go in yet. A possible example could be . will only accept a type of where . It will then return a value of type . However, if is unknown, it will be rejected as the type checker does not know if is guaranteed to be greater than .
I am planning to mostly copy Haskell's function application syntax, which are expressions seperated by spaces with application being left-associative. This will also mean functions are curried. (hence a 2-ary function would be of )
+ 1 2 # addition
row (* 2) (iota 5) # the first 5 multiples of 2
The data type of an expression is,
data STExpr a
= STExprAtom STAtom
| STExprArray [STExpr a] a
| STExprApply (STExpr a) (STExpr a) a
deriving FunctorI have decided to make this into a functor to make attaching data (such as source location and type information) to expressions easier
The data type of a type in STAPLE is,
data STType
= STTypeArray STShape STType
| STTypeInt -- Other scalar types will come eventually
| STTypeFun (STType -> Either TypeError STType)
data STShape
= STShapeUnknown
| STShapeKnown Int
instance Eq STShape where
(STShapeKnown x) == (STShapeKnown y) = x == y
STShapeUnknown == _ = False
_ == STShapeUnknown = FalseIn the case of STTypeFun, the
input type could be out of the domain, forcing us to raise a type
error.
STExprApply on
a function type will evaluate the function in STTypeFun,
either giving a type error if it does not satisfy the domain or the
codomain type of the function depending on the input type.
As an array programming language, STAPLE will support pervasive arithmetic operations.
For a 2-ary pervasive function, the base case of a pervasive function is when at least one of its parameters is a scalar. The function will thn apply to all scalars within the other array.
For example,
+ 2 [3 4 6] # [5 6 8]
In the case where both parameters are an array with equal axis (if the axis is unequal, it is a type error), We recurse down an axis until we reach the base case,
* [1 0] [[3 5] [6 7]]
[(* [1 0] [3 5]) (* [1 0] [6 7])]
[[(* 1 3) (* 0 5)] [(* 1 6) (* 0 7)]]
[[3 0] [6 0]]
The type of a 2-ary pervasive function is determined by maximium of the two input shapes (shape being the list of axes of an array, since an array type is similar to a linked list)
For a 1-ary pervasive function, the function just applies to every scalar in the array. Hence the function type would be
void*
with runtime type information. I am unsure how I would soundly implement
such a feature.I am thinking of writing a simple interpreter for this language first. Afterwards, I would like to get people to test this language. If this idea really works, I will consider making a webassembly compiler for it.
In terms of design, I have yet to create a module syntax that binds expressions into names. I would also like to explore that instead of having an unknown array axis, there is an axis that guarantees the smallest possible size of an array.
The main two languages I am inspired by are Uiua and Haskell.
I would also like to thank Madeline Vergani for her blog on her own array programming language. These series of posts have gave me some guideance and motivation to work and post on this project.