This commit is contained in:
Alexander 2025-06-10 13:15:24 -04:00
parent 864544624c
commit a3e82f34b5
246 changed files with 4433 additions and 2 deletions

@ -1 +0,0 @@
Subproject commit fd249264cd9617a0ff8b3306e8d94538c47f1759

View file

@ -0,0 +1,841 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>
Overview of the GP1 Programming Language
</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/css/index.css">
<link rel="icon" type="image/png" href="/assets/favicon.png">
<script>
const class_ = `font-${window.devicePixelRatio >= 1.3 ? 'hidpi' : 'lodpi'}`;
document.documentElement.className = class_;
</script>
<meta name="generator" content="soupault">
</head>
<body>
<main class="container">
<h1 id="programming-language-general-purpose-1">
Overview of the <br>GP1 Programming Language
</h1>
<p>
GP1 is a statically typed, multi-paradigm programming language with
an emphasis on brevity and explicitness. It provides both value and
reference types, as well as higher-order functions and first-class
support for many common programming patterns.
</p>
<p>
This document serves as a quick, informal reference for developers of GP1 (or anyone who's curious).
</p>
<h2 id="variables-and-constants">
Variables and Constants
</h2>
<p>
A given "variable" is defined with either the <code>var</code> or
<code>con</code> keyword, for mutable and immutable assignment
respectively, alonside the assignment operator, <code>&lt;-</code>. An
uninitialized variable MUST have an explicit type, and cannot be
accessed until it is assigned. A variable that is initialized in its
declaration may have an explicit type, but the type may be inferred
here, when possible, if one is omitted. Normal type-coercion rules apply
in assignments, as described in the <em>Coercion and Casting</em>
section.
</p>
<p>
Non-ascii unicode characters are allowed in variable names as long as
the character doesn't cause a parsing issue. For example, whitespace
tokens are not allowed in variable names.
</p>
<p>
Some examples of assigning variables:
</p>
<pre class="gp1"><code>var x: i32; // x is an uninitialized 32-bit signed integer
var y &lt;- x; // this won't work, because x has no value
x &lt;- 7;
var y &lt;- x; // this time it works, because x is now 7
con a: f64 &lt;- 99.8; // a is immutable
a &lt;- 44.12; // this doesn't work, because con variables cannot be reassigned</code></pre>
<p>
The following lines are equivalent,
</p>
<pre class="gp1"><code>con a &lt;- f64(7.2);
con a: f64 &lt;- 7.2;
con a &lt;- 7.2; // 7.2 is implicitly of type f64
con a &lt;- 7.2D; // With an explicit type suffix</code></pre>
<p>
as are these.
</p>
<pre class="gp1"><code>var c: f32 &lt;- 9;
var c &lt;- f32(9);
var c: f32 &lt;- f32(9);
var c &lt;- 9F;</code></pre>
<p>
Variable assignments are expressions in GP1, which can enable some
very interesting code patterns. For example, it allows multiple
assignments on one line with the following syntax.
<code>con a &lt;- var b &lt;- "death and taxes"</code> assigns the
string <code>"death and taxes"</code> to both <code>a</code> and
<code>b</code>, leaving you with one constant and one variable
containing separate instances of identical data. This is equivalent to
writing <code>con a &lt;- "death and taxes"</code> and
<code>var b &lt;- "death and taxes"</code> each on their own line.
Assignment as an expression also eliminates much of the need to define
variables immediately before the control structure in which they're
used, which improves readability.
</p>
<h2 id="intrinsic-types">
Intrinsic Types
</h2>
<h3 id="numeric-types">
Numeric Types
</h3>
<p>
<code>u8</code> <code>u16</code> <code>u32</code> <code>u64</code>
<code>u128</code> <code>u256</code> <code>usize</code>
<code>byte</code>
</p>
<p>
<code>i8</code> <code>i16</code> <code>i32</code> <code>i64</code>
<code>i128</code> <code>i256</code> <code>isize</code>
</p>
<p>
<code>f16</code> <code>f32</code> <code>f64</code> <code>f128</code>
<code>f256</code>
</p>
<p>
GP1 has signed integer, unsigned integer, and floating point numeric
types. Numeric types take the form of a single-letter indicator followed
by the type's size in bits. The indicators are <strong>i</strong>
(signed integer), <strong>u</strong> (unsigned integer), and
<strong>f</strong> (floating point). <code>usize</code> and
<code>isize</code> are pointer-width types. For example, on a 64-bit
system, <code>usize</code> is a 64-bit unsigned integer. However, it
must be cast to <code>u64</code> when assigning to a <code>u64</code>
variable. The type <code>byte</code> is an alias for <code>u8</code>.
Numeric operators are as one expects from C, with the addition of
<code>**</code> as a power operator.
</p>
<p>
Numeric literals have an implicit type, or the type can be specified
by a case-insensitive suffix. For example:
</p>
<pre class="gp1"><code>var i1 &lt;- 1234; // implicitly i32
var f1 &lt;- 1234.5; // implicitly f64
var i3 &lt;- 1234L; // i64
var u3 &lt;- 1234ui; // u32
var f2 &lt;- 1234.6F; // f32</code></pre>
<p>
The complete set of suffixes is given.
</p>
<table>
<thead>
<tr class="header">
<th>
suffix
</th>
<th>
corresponding type
</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>
s
</td>
<td>
i16
</td>
</tr>
<tr class="even">
<td>
i
</td>
<td>
i32
</td>
</tr>
<tr class="odd">
<td>
l
</td>
<td>
i64
</td>
</tr>
<tr class="even">
<td>
p
</td>
<td>
isize
</td>
</tr>
<tr class="odd">
<td>
b
</td>
<td>
byte
</td>
</tr>
<tr class="even">
<td>
us
</td>
<td>
u16
</td>
</tr>
<tr class="odd">
<td>
ui
</td>
<td>
u32
</td>
</tr>
<tr class="even">
<td>
ul
</td>
<td>
u64
</td>
</tr>
<tr class="odd">
<td>
up
</td>
<td>
usize
</td>
</tr>
<tr class="even">
<td>
f
</td>
<td>
f32
</td>
</tr>
<tr class="odd">
<td>
d
</td>
<td>
f64
</td>
</tr>
<tr class="even">
<td>
q
</td>
<td>
f128
</td>
</tr>
</tbody>
</table>
<h3 id="booleans">
Booleans
</h3>
<p>
<code>bool</code> is the standard boolean type with support for all
the usual operations. The boolean literals are <code>true</code> and
<code>false</code>. Bool operators are as one expects from C, with the
exception that NOT is <code>!!</code> instead of <code>!</code>.
</p>
<h3 id="bitwise-operators">
Bitwise Operators
</h3>
<p>
Bitwise operators can be applied only to integers and booleans. They
are single counterparts of the doubled boolean operators, e.g. boolean
negation is <code>!!</code>, so bitwise negation is <code>!</code>.
</p>
<h3 id="strings-and-characters">
Strings and Characters
</h3>
<p>
<code>char</code> is a unicode character of variable size. Char
literals are single-quoted, e.g. <code>'c'</code>. Any single valid char
value can be used as a literal in this fasion.
</p>
<p>
<code>string</code> is a unicode string. String literals are
double-quoted, e.g. <code>"Hello, World."</code>.
</p>
<h3 id="arrays">
Arrays
</h3>
<p>
GP supports typical array operations.
</p>
<pre class="gp1"><code>var tuples : (int, int)[]; // declare array of tuples
var strings : string[]; // declare array of strings
var array &lt;- i32[n]; // declare and allocate array of n elements
// n is any number that can be coerced to usize
con nums &lt;- {1, 2, 3}; // immutable array of i32
</code></pre>
<p>
Use the <code>length</code> property to access the number of elements
in an allocated array. Attempting to access <code>length</code> of an
unallocated array is an exception.
</p>
<pre class="gp1"><code>
var colors &lt;- {"Red", "White", "Blue"}; // allocate array
var count &lt;- colors.length; // count is usize(3)
</code></pre>
<p>
Arrays can be indexed with any integer type (signed or unsigned).
Negative values wrap from the end (-1 is the last element). An exception
occurs if the value is too big, i.e.no modulo operation is
performed.
</p>
<pre class="gp1"><code>var w &lt;- {1, 2, 3, 4, 5, 6, 7};
w[0] // first element, 1
w[-1] // last element, 7
var x &lt;- isize(-5);
w[x] // 5th to last element, 3
</code></pre>
<h3 id="tuples">
Tuples
</h3>
<p>
Tuples group multiple values into a single value with anonymous,
ordered fields. <code>()</code> is an empty tuple.
<code>("hello", i32(17))</code> is a tuple of type
<code>(string i32)</code>. Tuple fields are named like indices,
i.e.<code>(u128(4), "2").1</code> would be <code>"2"</code>.
</p>
<p>
The unit type, represented as a 0-tuple, is written
<code>()</code>.
</p>
<h3 id="regex">
Regex
</h3>
<p>
<code>regex</code> is a regular expression. GP1 regex format is
identical to that of .NET 5 and very similar to that of gawk.
</p>
<h2 id="named-functions">
Named Functions
</h2>
<p>
Some examples of defining named functions:
</p>
<pre class="gp1"><code>fn sum(a: f32, b: f32): f32 { a + b } // takes parameters and returns an f32
fn twice_println(s: string) { // takes parameters and implicitly returns ()
println("${s}\n${s}");
}
fn join_println(a: string, b: string): () { // takes parameters and explicitly returns ()
println("${a} ${b}");
}
fn seven(): u32 { 7 } // takes no parameters and returns the u32 value of 7</code></pre>
<p>
There are a number of syntaxes allowed for calling a given function.
This is because the caller is allowed to assign to zero or more of that
function's parameters by name. Parameters assigned by name are freely
ordered, while those assigned normally bind to the first parameter
ordered from left to right in the function definition that is
unassigned. With regard to the <code>join_println</code> function
defined above, this means that all of the following are valid and behave
identically.
</p>
<pre class="gp1"><code>join_println(a &lt;- "Hello,", b &lt;- "World.");
join_println(b &lt;- "World.", a &lt;- "Hello,");
join_println(b &lt;- "World.", "Hello,");
join_println("Hello,", "World.");</code></pre>
<p>
Function names may be overloaded. For example,
<code>join_println</code> could be additionally defined as
</p>
<pre class="gp1"><code>fn join_println(a: string, b: string, sep: string) {
println("${a}${sep}${b}");
}</code></pre>
<p>
and then both <code>join_println("Hello,", "World.", " ")</code> and
<code>join_println("Hello,", "World.")</code> would be valid calls.
</p>
<p>
Functions may be defined and called within other functions. You may
be familar with this pattern from functional languages like F#, wherein
a wrapper function is often used to guard an inner recursive function
(GP1 permits both single and mutual recursion in functions). For
example:
</p>
<pre class="gp1"><code>fn factorial(n: u256): u256 {
fn aux(n: u256, accumulator: u256): u256 {
match n &gt; 1 {
true =&gt; aux(n - 1, accumulator * n),
_ =&gt; accumulator,
}
}
aux(n, 1)
}</code></pre>
<p>
Arguments are passed by value by default. For information on the
syntax used in this example, refer to <em>Control Flow</em>.
</p>
<h2 id="anonymous-functions">
Anonymous Functions
</h2>
<h3 id="closures">
Closures
</h3>
<p>
Closures behave as one would expect in GP1, exactly like they do in
most other programming languages that feature them. Closures look like
this:
</p>
<pre class="gp1"><code>var x: u32 &lt;- 8;
var foo &lt;- { y, z =&gt; x * y * z}; // foo is a closure; its type is fn&lt;u32 | u32&gt;
assert(foo(3, 11) == (8 * 3 * 11)); // true
x &lt;- 5;
assert(foo(3) == (8 * 3 * 11)); // true
con bar &lt;- { =&gt; x * x }; // bar is a closure of type `fn&lt;u32&gt;`
assert(bar() == 25); // true because closure references already-defined x</code></pre>
<p>
They are surrounded by curly braces. Within the curly braces goes an
optional, comma-separated parameter list, followed by a required
<code>=&gt;</code> symbol, followed by an optional expression. If no
expression is included, the closure implicitly returns
<code>()</code>.
</p>
<p>
The reason the match-expression uses the same <code>=&gt;</code>
symbol is because the <code>when</code> section of a match arm is an
implicit closure. The reason <code>=&gt;</code> in particular was chosen
for closures is twofold. One, arrows are conventional for expressing
anonymous functions, and two, the space between the lines of an equals
sign is enclosed by them.
</p>
<h3 id="lambdas">
Lambdas
</h3>
<p>
Lambdas are nearly identical to closures, but they don't close over
their environment, and they use the <code>-&gt;</code> symbol in place
of <code>=&gt;</code>. A few examples of lambdas:
</p>
<pre class="gp1"><code>con x: u32 &lt;- 4; // this line is totally irrelevant
con square &lt;- { x -&gt; x * x }; // this in not valid, because the type of the function is not known
con square &lt;- { x: u32 -&gt; x * x }; // this if fine, because the type is specified in the lambda
con square: fn&lt;u32 | u32&gt; &lt;- { x -&gt; x * x }; // also fine, because the type is specified in the declaration</code></pre>
<h2 id="function-types">
Function Types
</h2>
<p>
Functions are first-class citizens in GP1, so you can assign them to
variables, pass them as arguments, &amp;c.However, using the function
definition syntax is suboptimal when using function types. Instead,
there is a separate syntax for function types. Given the function
<code>fn sum(a: f64, b: f64): f64 { a + b }</code> the function type is
expressed <code>fn&lt;f64 f64 | f64&gt;</code>, meaning a function that
accepts two f64 values and returns an f64. Therefore,
</p>
<pre class="gp1"><code>fn sum(a: f64, b: f64): f64 { a + b } </code></pre>
<pre class="gp1"><code>con sum: fn&lt;f64 f64 | f64&gt; &lt;- { a, b -&gt; a + b };</code></pre>
<pre class="gp1"><code>con sum &lt;- { a: f64, b: f64 -&gt; a + b };</code></pre>
<p>
are all equivalent ways of binding a function of type
<code>fn&lt;f64 f64 | f64&gt;</code> to the constant <code>sum</code>.
Here's an example of how to express a function type for a function
argument.
</p>
<pre class="gp1"><code>fn apply_op(a: i32, b: i32, op: fn&lt;i32 i32 | i32&gt;): i32 {
op(a, b)
}</code></pre>
<h3 id="function-type-inference">
Function Type Inference
</h3>
<p>
The above example provides an explicit type for the argument
<code>op</code>. You could safely rewrite this as
</p>
<pre class="gp1"><code>fn apply_op(a: i32, b: i32, op: fn): i32 {
op(a, b)
}</code></pre>
<p>
because the compiler can safely infer the function type of
<code>op</code>. Type inference only works to figure out the function
signature, so <code>fn apply_op(a:i32, b:i32, op):i32 { . . . }</code>
is not allowed.
</p>
<h2 id="coercion-and-casting">
Coercion and Casting
</h2>
<p>
Refer to <em>Variables and Constants</em> for information on the
syntax used in this section.
</p>
<p>
Numeric types are automatically coerced into other numeric types as
long as that coercion is not lossy. For example,
</p>
<pre class="gp1"><code>var x: i32 &lt;- 10;
var y: i64 &lt;- x;</code></pre>
<p>
is perfectly legal (the 32-bit value fits nicely in the 64-bit
variable). However, automatic coercion doesn't work if it would be
lossy, so
</p>
<pre class="gp1"><code>var x: i64 &lt;- 10;
var y: i32 &lt;- x;</code></pre>
<p>
doesn't work. This holds for numeric literals as well.
Unsurprisingly, <code>var x: i32 &lt;- 3.14</code> wouldn't compile. The
floating point value can't be automatically coerced to an integer type.
So what does work? Casting via the target type's pseudo-constructor
works.
</p>
<pre class="gp1"><code>con x: f64 &lt;- 1234.5; // okay because the literal can represent any floating point type
con y: f64 &lt;- f16(1234.5); // also okay, because any f16 can be losslessly coerced to an f64
con z: i32 &lt;- i32(x); // also okay; uses the i32 pseudo-constructor to 'cast' x to a 32-bit integer
assert(z == 1234)
con a: f64 &lt;- 4 * 10 ** 38; // this value is greater than the greatest f32
con b: f32 &lt;- f32(a); // the value of b is the maximum value of f32</code></pre>
<p>
This approach is valid for all intrinsic types. For example,
<code>var flag: bool &lt;- bool(0)</code> sets <code>flag</code> to
<code>false</code> and <code>var txt: string &lt;- string(83.2)</code>
sets <code>txt</code> to the string value <code>"83.2"</code>. Such
behavior can be implemented by a programmer on their own types via a
system we'll discuss in the <em>Interfaces</em> section.
</p>
<h2 id="program-structure">
Program Structure
</h2>
<p>
Every GP1 program has an entry-point function. Within that function,
statements are executed from top to bottom and left to right. The
entry-point function can be declared with the <code>entry</code> keyword
in place of <code>fn</code> and returns an integer, which will be
provided to the host operating system as an exit code. Naturally, this
means that the handling of that code is platform-dependent once it
passes the program boundry, so it's important to keep in mind that a
system may implicitly downcast or otherwise modify it before it is made
available to the user. If no exit code is specified, or if the return
type of the function is not an integer, GP1 assumes an exit code of
<code>usize(0)</code> and returns that to the operating system.
</p>
<p>
The following program prints Hello, World. and exits with an error
code.
</p>
<pre class="gp1"><code>entry main(): usize {
hello_world();
1
}
fn hello_world() {
println("Hello, World.");
}</code></pre>
<p>
The entry function may have any name; it's the <code>entry</code>
keyword that makes it the entry point. The entry function may also be
implicit. If one is not defined explicitly, the entire file is treated
as being inside an entry function. Therefore,
</p>
<pre class="gp1"><code>println("Hello, World.");</code></pre>
<p>
is a valid and complete program identical to
</p>
<pre class="gp1"><code>entry main(): usize {
println("Hello, World.");
}</code></pre>
<p>
This behavior can lend GP1 a very flexible feeling akin to many
scripting languages.
</p>
<p>
In a program where there is an entry-point specified, only
expressions made within that function will be evaluated. This means that
the following program does NOT print anything to the console.
</p>
<pre class="gp1"><code>entry main(): usize {
con x: usize &lt;- 7;
}
println("This text will not be printed.");</code></pre>
<p>
In fact, this program is invalid. Whenever there is an explicit entry
point, no statements may be made in the global scope.
</p>
<h2 id="control-flow">
Control Flow
</h2>
<h3 id="conditionals">
Conditionals
</h3>
<p>
At this time, GP1 has only one non-looping conditional control
structure, in two variants: <code>match</code> and
<code>match all</code>. The syntax is as follows, where
<code>*expr*</code> are expressions and <code>pattern*</code> are
pattern matching options (refer to <em>Pattern Matching</em> for more
info).
</p>
<pre class="gp1"><code>match expr {
pattern1 =&gt; arm_expr1,
pattern2 =&gt; arm_expr2,
_ =&gt; arm_expr3,
}</code></pre>
<p>
The <code>match</code> expression executes the first arm that matches
the pattern passed in <code>expr</code>. The <code>match all</code>
expression executes all arms that match the pattern. Both flavors return
their last executed expression.
</p>
<p>
The <code>when</code> keyword may be used in a given match arm to
further restrict the conditions of execution, e.g.
</p>
<pre class="gp1"><code>con fs &lt;- 43;
con is_even &lt;- match fs {
n when n % 2 == 0 =&gt; " is "
_ =&gt; " is not "
};
print(fs + is_even + "even.")</code></pre>
<h3 id="loops">
Loops
</h3>
<p>
Several looping structures are supported in GP1
</p>
<ul>
<li>
<code>loop</code>
</li>
<li>
<code>for</code>
</li>
<li>
<code>while</code>
</li>
<li>
<code>do/while</code>
</li>
</ul>
<p>
along with <code>continue</code> and <code>break</code> to help
control program flow. All of these are statements.
</p>
<pre class="gp1"><code>loop { . . . } // an unconditional loop -- runs forever or until broken</code></pre>
<pre class="gp1"><code>for i in some_iterable { . . . } // loop over anything that is iterable</code></pre>
<pre class="gp1"><code>while some_bool { . . . } // classic conditional loop that executes until the predicate is false</code></pre>
<pre class="gp1"><code>do { . . .
} while some_bool // traditional do/while loop that ensures body executes at least once</code></pre>
<h2 id="pattern-matching">
Pattern Matching
</h2>
<p>
Pattern matching behaves essentially as it does in SML, with support
for various sorts of destructuring. It works in normal assignment and in
<code>match</code> arms. It will eventually work in function parameter
assignment, but perhaps not at first.
</p>
<p>
For now, some examples.
</p>
<pre class="gp1"><code>a &lt;- ("hello", "world"); // a is a tuple of strings
(b, c) &lt;- a;
assert(b == "hello" &amp;&amp; c == "world")
fn u32_list_to_string(l: List&lt;u32&gt;): string { // this is assuming that square brackets are used for linked lists
con elements &lt;- match l {
[] =&gt; "",
[e] =&gt; string(e),
h::t =&gt; string(h) + ", " + u32_list_to_string(t), // the bit before the arrow in each arm is a pattern
} // h::t matches the head and tail of the list to h and t, respectively
"[" + elements + "]" // [s] matches any single-element list
} // [] matches any empty list</code></pre>
<h2 id="interfaces">
Interfaces
</h2>
<p>
Interfaces are in Version 2 on the roadmap.
</p>
<h2 id="user-defined-types">
User-Defined Types
</h2>
<h3 id="enums">
Enums
</h3>
<p>
Enums are pretty powerful in GP1. They can be the typical enumerated
type you'd expect, like
</p>
<pre class="gp1"><code>enum Coin { penny, nickle, dime, quarter } // 'vanilla' enum
var a &lt;- Coin.nickle
assert a == Coin.nickle
</code></pre>
<p>
Or an enum can have an implicit field named <code>value</code>
</p>
<pre class="gp1"><code>enum Coin: u16 { penny(1), nickle(5), dime(10), quarter(25) }
var a &lt;- Coin.nickle;
assert(a == Coin.nickle);
assert(a.value == 5);</code></pre>
<p>
Or an enum can be complex with a user-defined set of fields, like
</p>
<pre class="gp1"><code>enum CarModel(make: string, mass: f32, wheelbase: f32) { // enum with multiple fields
gt ( "ford", 1581, 2.71018 ),
c8_corvette ( "chevy", 1527, 2.72288 )
}</code></pre>
<p>
A field can also have a function type. For example
</p>
<pre class="gp1"><code>enum CarModel(make: string, mass: f32, wheelbase: f32, gasUsage: fn&lt;f32 | f32&gt;) {
gt ( "ford", 1581, 2.71018, { miles_traveled -&gt; miles_traveled / 14 } ),
c8_corvette ( "chevy", 1527, 2.72288, { miles_traveled -&gt; miles_traveled / 19 } )
}
var my_car &lt;- CarModel.c8_corvette;
var gas_used &lt;- my_car.gasUsage(200); // estimate how much gas I'd use on a 200 mile trip</code></pre>
<p>
Equivalence of enums is not influenced by case values, e.g.
</p>
<pre class="gp1"><code>enum OneOrAnother: u16 { one(0), another(0) }
con a &lt;- OneOrAnother.one;
con b &lt;- OneOrAnother.another;
assert(a != b);
assert(a.value == b.value);</code></pre>
<p>
It's important to remember that enums are 100% always totally in
every concieveable fashion immutable. To make this easier to enforce,
only value types are allowed for enum fields.
</p>
<h3 id="records">
Records
</h3>
<p>
Records are record types, defined with the <code>record</code>
keyword. Fields are defined in the <code>record</code> block and
behavior is defined in the optional <code>impl</code> block.
</p>
<p>
For example,
</p>
<pre class="gp1"><code>record Something {
label: i32 // field label followed by some type
} impl { . . . } // associated functions. This is different than having functions in the fields section because impl functions are not assignable.</code></pre>
<p>
If the record implements some interface, <code>SomeInterface</code>,
the <code>impl</code> would be replaced with
<code>impl SomeInterface</code>, and the functions of
<code>SomeInterface</code> would be defined alongside any other
functions of the <code>Something</code> record.
</p>
<h3 id="unions">
Unions
</h3>
<p>
Unions are the classic discriminated sum type.
</p>
<pre class="gp1"><code>union BinaryTree {
Empty,
Leaf: i32,
Node: (BinaryTree BinaryTree),
}</code></pre>
<h3 id="type-aliases">
Type Aliases
</h3>
<p>
Refer to <em>Generics</em> for info on the syntax used in this
section.
</p>
<p>
Type aliasing is provided with the <code>type</code> keyword,
e.g.
</p>
<pre class="gp1"><code>type TokenStream Sequence&lt;Token&gt;
type Ast Tree&lt;AbstractNode&gt;
fn parse(ts: TokenStream): Ast { . . . }</code></pre>
<p>
Notice how much cleaner the function definition looks with the
aliased types. This keyword is useful mainly for readability and domain
modeling.
</p>
<h2 id="generics">
Generics
</h2>
<p>
Generics are in Version 2 on the official GP1 roadmap. They roughly
use C++ template syntax or Rust generic syntax.
</p>
<h2 id="references-and-reference-types">
References and Reference
Types
</h2>
<p>
GP1 has three operators involved in handling references,
<code>#</code>, <code>&amp;</code>, and <code>@</code>. These are
immutable reference, mutable reference, and dereference, respectively.
Some examples of referencing/dereferencing values:
</p>
<pre class="gp1"><code>var a &lt;- "core dumped";
var b &lt;- &amp;a; // b is a mutable reference to a
assert(a == @b);
assert(a != b);
@b &lt;- "missing ; at line 69, column 420";
assert(a == "missing ; at line 69, column 420");
b &lt;- &amp;"missing ; at line 420, column 69";
assert(a != "missing ; at line 420, column 69");
var c &lt;- #b; // c is an immutable reference to b
assert(@c == b);
assert(@@c == a);
@c &lt;- &amp;"kablooey"; // this does not work. `c` is an immutable reference and cannot be used to assign its referent.</code></pre>
<p>
Naturally, only <code>var</code> values can be mutated through
references.
</p>
<p>
The reference operators may be prepended to any type, T, to describe
the type of a reference to a value of type T, e.g.
</p>
<pre class="gp1"><code>fn set_through(ref: &amp;string) { // this function takes a mutable reference to a string and returns `()`
@ref &lt;- "goodbye";
}
var a &lt;- "hello";
set_through(&amp;a);
assert(a == "goodbye");</code></pre>
</main>
</body>
</html>

View file

@ -0,0 +1,93 @@
Copyright 2011 The Alegreya Project Authors (https://github.com/huertatipografica/Alegreya)
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://openfontlicense.org
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

View file

@ -0,0 +1,75 @@
Alegreya Variable Font
======================
This download contains Alegreya as both variable fonts and static fonts.
Alegreya is a variable font with this axis:
wght
This means all the styles are contained in these files:
Alegreya-VariableFont_wght.ttf
Alegreya-Italic-VariableFont_wght.ttf
If your app fully supports variable fonts, you can now pick intermediate styles
that arent available as static fonts. Not all apps support variable fonts, and
in those cases you can use the static font files for Alegreya:
static/Alegreya-Regular.ttf
static/Alegreya-Medium.ttf
static/Alegreya-SemiBold.ttf
static/Alegreya-Bold.ttf
static/Alegreya-ExtraBold.ttf
static/Alegreya-Black.ttf
static/Alegreya-Italic.ttf
static/Alegreya-MediumItalic.ttf
static/Alegreya-SemiBoldItalic.ttf
static/Alegreya-BoldItalic.ttf
static/Alegreya-ExtraBoldItalic.ttf
static/Alegreya-BlackItalic.ttf
Get started
-----------
1. Install the font files you want to use
2. Use your app's font picker to view the font family and all the
available styles
Learn more about variable fonts
-------------------------------
https://developers.google.com/web/fundamentals/design-and-ux/typography/variable-fonts
https://variablefonts.typenetwork.com
https://medium.com/variable-fonts
In desktop apps
https://theblog.adobe.com/can-variable-fonts-illustrator-cc
https://helpx.adobe.com/nz/photoshop/using/fonts.html#variable_fonts
Online
https://developers.google.com/fonts/docs/getting_started
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide
https://developer.microsoft.com/en-us/microsoft-edge/testdrive/demos/variable-fonts
Installing fonts
MacOS: https://support.apple.com/en-us/HT201749
Linux: https://www.google.com/search?q=how+to+install+a+font+on+gnu%2Blinux
Windows: https://support.microsoft.com/en-us/help/314960/how-to-install-or-remove-a-font-in-windows
Android Apps
https://developers.google.com/fonts/docs/android
https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts
License
-------
Please read the full license text (OFL.txt) to understand the permissions,
restrictions and requirements for usage, redistribution, and modification.
You can use them in your products & projects print or digital,
commercial or otherwise.
This isn't legal advice, please consider consulting a lawyer and see the full
license for all details.

View file

@ -0,0 +1,93 @@
Copyright 2013 The Alegreya Sans Project Authors (https://github.com/huertatipografica/Alegreya-Sans)
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://openfontlicense.org
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

View file

@ -0,0 +1 @@
b481aac1-ef8d-48d0-8d6b-b109c992addd

View file

@ -0,0 +1 @@
{"weight":350,"italic":false,"alternates":{"cv01":false,"cv02":false,"cv03":false,"cv04":false,"cv05":false,"cv06":true,"cv07":false,"cv08":true,"cv09":false,"cv10":false,"cv11":false},"features":{"ss01":false,"ss02":false,"ss03":false,"ss04":true,"ss05":true},"letterSpacing":0,"lineHeight":1,"fontName":"UnfancyDevN"}

View file

@ -0,0 +1,11 @@
A short guide for how to install and enable your shiny new version of Commit Mono.
This is taken from section 08 Install from https://commitmono.com/
#1 (Download the fonts)
#2 Unzip the fonts. You'll see 4 font files. These 4 fonts make up a 'Style Group':
* CommitMono-Regular: Base version with settings and weight of your choice.
* CommitMono-Italic: An italic version, same weight as regular.
* CommitMono-Bold: A bold version, weight 700.
* CommitMono-BoldItalic: A bold version, weight 700, that is also italic.
#3 Install all 4 fonts on your system:
* Windows: Right click the font in the folder and click "Instal

View file

@ -0,0 +1,37 @@
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the compon

70
acl.cool/serve/cats.ml Normal file
View file

@ -0,0 +1,70 @@
module type Functor = sig
type 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
end
module type Applicative = sig
type 'a t
val pure : 'a -> 'a t
val apply : ('a -> 'b) t -> 'a t -> 'b t
end
module type Monad = sig
type 'a t
val return : 'a -> 'a t
val bind : ('a -> 'b t) -> 'a t -> 'b t
end
module ApplicativeOfMonad (M : Monad) : Applicative with type 'a t = 'a M.t = struct
type 'a t = 'a M.t
let pure = M.return
let apply f x = M.(bind (fun y -> bind (fun g -> return (g y)) f) x)
end
module FunctorOfApplicative (A : Applicative) : Functor with type 'a t = 'a A.t = struct
type 'a t = 'a A.t
let map f x = A.(apply (pure f) x)
end
module FunctorOfMonad (M : Monad) : Functor with type 'a t = 'a M.t = struct
include FunctorOfApplicative(ApplicativeOfMonad(M))
end
module MonadDerive (M : Monad) = struct
include M
include ApplicativeOfMonad(M)
include FunctorOfMonad(M)
let (>>=) x f = bind f x
let (<$>) x f = map x f
let (<*>) x f = apply x f
end
module ListMonad = struct
type 'a t = 'a list
let return x = [x]
let rec bind (f : 'a -> 'b list) : 'a list -> 'b list = function
| [] -> []
| x :: xs -> f x @ bind f xs
end
module Dlm = MonadDerive(ListMonad)
let pair x y = x, y
let cart_prod xs ys = Dlm.(pair <$> xs <*> ys)
let () = cart_prod [1;2;3;4] ["7"; "hello there"; "forthwith!"]
|> List.iter (fun (x, y) -> print_endline @@ "(" ^ string_of_int x ^ ", " ^ y ^ ")")
(* ============================================================================================= *)
module StateMonad (S : sig type t end) = struct
type 'a t = S.t -> S.t * 'a
let return x s = (s, x)
let bind f x s = let s', a = x s in f a s'
end
module IntStateMonad = StateMonad(struct type t = int end)

View file

@ -0,0 +1,70 @@
module type Functor = sig
type 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
end
module type Applicative = sig
type 'a t
val pure : 'a -> 'a t
val apply : ('a -> 'b) t -> 'a t -> 'b t
end
module type Monad = sig
type 'a t
val return : 'a -> 'a t
val bind : ('a -> 'b t) -> 'a t -> 'b t
end
module ApplicativeOfMonad (M : Monad) : Applicative with type 'a t = 'a M.t = struct
type 'a t = 'a M.t
let pure = M.return
let apply f x = M.(bind (fun y -> bind (fun g -> return (g y)) f) x)
end
module FunctorOfApplicative (A : Applicative) : Functor with type 'a t = 'a A.t = struct
type 'a t = 'a A.t
let map f x = A.(apply (pure f) x)
end
module FunctorOfMonad (M : Monad) : Functor with type 'a t = 'a M.t = struct
include FunctorOfApplicative(ApplicativeOfMonad(M))
end
module MonadDerive (M : Monad) = struct
include M
include ApplicativeOfMonad(M)
include FunctorOfMonad(M)
let (>>=) x f = bind f x
let (<$>) x f = map x f
let (<*>) x f = apply x f
end
module ListMonad = struct
type 'a t = 'a list
let return x = [x]
let rec bind (f : 'a -> 'b list) : 'a list -> 'b list = function
| [] -> []
| x :: xs -> f x @ bind f xs
end
module Dlm = MonadDerive(ListMonad)
let pair x y = x, y
let cart_prod xs ys = Dlm.(pair <$> xs <*> ys)
let () = cart_prod [1;2;3;4] ["7"; "hello there"; "forthwith!"]
|> List.iter (fun (x, y) -> print_endline @@ "(" ^ string_of_int x ^ ", " ^ y ^ ")")
(* ============================================================================================= *)
module StateMonad (S : sig type t end) = struct
type 'a t = S.t -> S.t * 'a
let return x s = (s, x)
let bind f x s = let s', a = x s in f a s'
end
module IntStateMonad = StateMonad(struct type t = int end)

Some files were not shown because too many files have changed in this diff Show more