2021-03-26 12:31:55 -07:00
|
|
|
|
# The Ivo Programming Language
|
|
|
|
|
Ivo (IPA: /aɪvoʊ/) is a programming language intended
|
|
|
|
|
as a tool for its author to explore interesting programming language features.
|
2019-08-15 10:42:24 -07:00
|
|
|
|
|
2021-03-26 12:31:55 -07:00
|
|
|
|
Ivo is currently in a very early stage of development
|
|
|
|
|
and most likely is not of any practical or academic interest;
|
|
|
|
|
however, that may change in the future.
|
|
|
|
|
This README serves to document the language as it currently stands,
|
|
|
|
|
not what the language one day hopes to be.
|
2021-03-05 23:38:21 -08:00
|
|
|
|
|
2021-03-26 12:31:55 -07:00
|
|
|
|
## Using the Ivo interpreter
|
|
|
|
|
You may run the Ivo interpreter using `stack run`;
|
|
|
|
|
the interpreter does not take any arguments.
|
|
|
|
|
|
|
|
|
|
Type in your command, definition, or expression at the prompt: `>> `.
|
|
|
|
|
Expressions will be typechecked, evaluated using call-by-value, and then printed.
|
2021-03-18 14:40:04 -07:00
|
|
|
|
|
|
|
|
|
Exit the prompt with `Ctrl-d` (or equivalent).
|
|
|
|
|
|
2021-03-26 12:31:55 -07:00
|
|
|
|
### Interpreter commands
|
2021-03-18 14:40:04 -07:00
|
|
|
|
These commands are available:
|
|
|
|
|
|
|
|
|
|
* `:clear`: Clear all of your variable definitions.
|
2021-03-26 12:31:55 -07:00
|
|
|
|
|
|
|
|
|
* `:load <filename>`:
|
|
|
|
|
|
|
|
|
|
Execute a file containing Ivo definitions and expressions in the interpreter.
|
|
|
|
|
Variables already defined in the interpreter will be defined in the file;
|
|
|
|
|
variables defined by the file will be defined in the interpreter.
|
|
|
|
|
|
|
|
|
|
The filename may contain spaces, but trailing whitespace will be trimmed.
|
|
|
|
|
|
2021-03-18 14:40:04 -07:00
|
|
|
|
* `:check <on/off> <always/decls/off>`:
|
2021-03-26 12:31:55 -07:00
|
|
|
|
|
|
|
|
|
* If the first argument is `on`,
|
|
|
|
|
then expressions will only be evaluated and definitions will only be added
|
|
|
|
|
only if typechecking succeeds.
|
|
|
|
|
|
|
|
|
|
* If the second argument is `always`, then inferred types will always be printed;
|
|
|
|
|
if it is `decls`, then only the inferred types of declarations will be printed;
|
|
|
|
|
otherwise, the type of expressions are never printed.'
|
|
|
|
|
|
2021-03-18 14:40:04 -07:00
|
|
|
|
* The default values are `on` `decls`.
|
2021-03-26 12:31:55 -07:00
|
|
|
|
|
2021-03-18 14:40:04 -07:00
|
|
|
|
* `:trace <off/local/global>`:
|
2021-03-26 12:31:55 -07:00
|
|
|
|
|
|
|
|
|
* If the argument is `local`, intermediate expressions will be printed
|
|
|
|
|
as they are evaluated;
|
|
|
|
|
|
|
|
|
|
* If the argument is `global`, the *entire* expression will be printed
|
|
|
|
|
with each evaluation step.
|
|
|
|
|
|
2021-03-18 14:40:04 -07:00
|
|
|
|
* The default value is `off`.
|
2019-08-19 15:08:45 -07:00
|
|
|
|
|
2021-03-26 12:31:55 -07:00
|
|
|
|
## The Ivo language
|
|
|
|
|
### Syntax
|
Add support for many data types, pattern matching, and literals.
* Data types: products, sums, naturals, lists, characters
* Literals: naturals, lists, characters, and strings
I also updated the description with examples of how to use all these new features.
The code's a bit messy and will need cleanup, but for now, it works!
2021-03-17 00:20:17 -07:00
|
|
|
|
The parser's error messages currently are virtually useless, so be very careful with your syntax.
|
2019-08-15 10:42:24 -07:00
|
|
|
|
|
Add support for many data types, pattern matching, and literals.
* Data types: products, sums, naturals, lists, characters
* Literals: naturals, lists, characters, and strings
I also updated the description with examples of how to use all these new features.
The code's a bit messy and will need cleanup, but for now, it works!
2021-03-17 00:20:17 -07:00
|
|
|
|
* Variable names: any sequence of letters.
|
|
|
|
|
* Function application: `f x y`
|
|
|
|
|
* Lambda abstraction: `\x y z. E` or `λx y z. E`
|
|
|
|
|
* Let expressions: `let x = E; y = F in G`
|
2021-03-22 17:34:51 -07:00
|
|
|
|
* Or letrec expressions, which can only define variable,
|
|
|
|
|
but which can be self-referential: `letrec x = ... x ... in E`
|
Add support for many data types, pattern matching, and literals.
* Data types: products, sums, naturals, lists, characters
* Literals: naturals, lists, characters, and strings
I also updated the description with examples of how to use all these new features.
The code's a bit messy and will need cleanup, but for now, it works!
2021-03-17 00:20:17 -07:00
|
|
|
|
* Parenthetical expressions: `(E)`
|
2021-03-18 00:00:43 -07:00
|
|
|
|
* Constructors: `()`, `(x, y)` (or `(,) x y`), `Left x`, `Right y`, `Z`, `S`, `[]`, `(x :: xs)` (or `(:) x xs`), `Char n`.
|
Add support for many data types, pattern matching, and literals.
* Data types: products, sums, naturals, lists, characters
* Literals: naturals, lists, characters, and strings
I also updated the description with examples of how to use all these new features.
The code's a bit messy and will need cleanup, but for now, it works!
2021-03-17 00:20:17 -07:00
|
|
|
|
* The parentheses around the cons constructor are not optional.
|
|
|
|
|
* `Char` takes a natural number and turns it into a character.
|
2021-03-22 17:34:51 -07:00
|
|
|
|
* Pattern matchers: `{ Left a -> e ; Right y -> f }`
|
Add support for many data types, pattern matching, and literals.
* Data types: products, sums, naturals, lists, characters
* Literals: naturals, lists, characters, and strings
I also updated the description with examples of how to use all these new features.
The code's a bit messy and will need cleanup, but for now, it works!
2021-03-17 00:20:17 -07:00
|
|
|
|
* Pattern matchers can be applied like functions, e.g. `{ Z -> x, S -> y } 10` reduces to `y`.
|
2021-03-18 00:00:43 -07:00
|
|
|
|
* Patterns must use the regular form of the constructor, e.g. `(x :: xs)` and not `((::) x xs)`.
|
Add support for many data types, pattern matching, and literals.
* Data types: products, sums, naturals, lists, characters
* Literals: naturals, lists, characters, and strings
I also updated the description with examples of how to use all these new features.
The code's a bit messy and will need cleanup, but for now, it works!
2021-03-17 00:20:17 -07:00
|
|
|
|
* There are no nested patterns or default patterns.
|
|
|
|
|
* Incomplete pattern matches will crash the interpreter.
|
|
|
|
|
* Literals: `1234`, `[e, f, g, h]`, `'a`, `"abc"`
|
|
|
|
|
* Strings are represented as lists of characters.
|
2021-03-18 00:00:43 -07:00
|
|
|
|
* Type annotations: there are no type annotations; types are inferred only.
|
2021-03-18 14:40:04 -07:00
|
|
|
|
* Comments: `// line comment`, `/* block comment */`
|
|
|
|
|
|
|
|
|
|
Top-level contexts (e.g. the REPL or a source code file)
|
2021-03-22 17:34:51 -07:00
|
|
|
|
allow declarations (`let(rec) x = E` without multiple definitions `in ...`),
|
2021-03-18 14:40:04 -07:00
|
|
|
|
which make your definitions available for the rest of the program's execution.
|
2021-03-22 17:34:51 -07:00
|
|
|
|
You must separate your declarations and expressions with `;`.
|
2021-03-18 00:00:43 -07:00
|
|
|
|
|
2021-03-26 12:31:55 -07:00
|
|
|
|
### Types
|
2021-03-18 00:00:43 -07:00
|
|
|
|
Types are checked/inferred using the Hindley-Milner type inference algorithm.
|
|
|
|
|
|
|
|
|
|
* Functions: `a -> b` (constructed by `\x. e`)
|
|
|
|
|
* Products: `a * b` (constructed by `(x, y)`)
|
|
|
|
|
* Unit: `★` (constructed by `()`)
|
|
|
|
|
* Sums: `a + b` (constructed by `Left x` or `Right y`)
|
|
|
|
|
* Bottom: `⊥` (currently useless because incomplete patterns are allowed)
|
|
|
|
|
* The natural numbers: `Nat` (constructed by `Z` and `S`)
|
|
|
|
|
* Lists: `List a` (constructed by `[]` and `(x :: xs)`)
|
|
|
|
|
* Characters: `Char` (constructed by `Char`, which takes a `Nat`)
|
|
|
|
|
* Universal quantification (forall): `∀a b. t`
|
2021-03-05 23:38:21 -08:00
|
|
|
|
|
2021-03-26 12:31:55 -07:00
|
|
|
|
### Builtins
|
2021-03-18 00:00:43 -07:00
|
|
|
|
Builtins are variables that correspond with a built-in language feature
|
|
|
|
|
that cannot be replicated by user-written code.
|
|
|
|
|
They still are just variables though; they do not receive special syntactic treatment.
|
2021-03-05 23:38:21 -08:00
|
|
|
|
|
2021-03-26 12:31:55 -07:00
|
|
|
|
* `callcc : ∀a b. (((a -> b) -> a) -> a)`:
|
|
|
|
|
[the call-with-current-continuation control flow operator](https://en.wikipedia.org/wiki/Call-with-current-continuation).
|
2021-03-05 23:38:21 -08:00
|
|
|
|
|
|
|
|
|
Continuations are printed as `λ!. ... ! ...`, like a lambda abstraction
|
|
|
|
|
with an argument named `!` which is used exactly once;
|
|
|
|
|
however, continuations are *not* the same as lambda abstractions
|
|
|
|
|
because they perform the side effect of modifying the current continuation,
|
2021-03-26 12:31:55 -07:00
|
|
|
|
and this is *not* valid syntax you can enter into the REPL.
|
Add support for many data types, pattern matching, and literals.
* Data types: products, sums, naturals, lists, characters
* Literals: naturals, lists, characters, and strings
I also updated the description with examples of how to use all these new features.
The code's a bit messy and will need cleanup, but for now, it works!
2021-03-17 00:20:17 -07:00
|
|
|
|
|
2021-03-26 12:31:55 -07:00
|
|
|
|
### Example code
|
|
|
|
|
You can see some example code in `examples/examples.ivo`.
|