The programming language for education
enum Tree[cov Element]:
case Leaf(value: Element)
case Node(value: Element, children: NonEmptyList[Tree[Element]])
-- Root is min
def minMax[Element](tree: Element): Tree[Element] = tree match
case Leaf(value) then value
case Node(_, children) then children.map(maxMin).minimum
-- Root is max
def maxMin[Element](tree: Element): Tree[Element] = tree match
case Leaf(value) then value
case Node(_, children) then children.map(minMax).maximum
Algorab is a programming language designed to meet the educational needs non-fulfilled by languages such as Python or C on high and higher education for teaching programming and algorithms. Using features such as strong static typing, meaningful error messages, ADTs and effect handlers, Algorab promotes effective learning of algorithms and good programming practices.
Algorab allows students to start practising quickly by being easy to install on all platforms and simple to use thanks to its low-ceremony syntax, allowing teachers to save time on the first lessons.
println("Hello World")
val name = ask("What's your name?")
println("Hello $name!")
print("Hello World")
name = input("What's your name?")
print(f"Hello {name}!")
printf("Hello World\n");
char word[256];
fgets(word, sizeof(word), stdin);
printf("Hello %s!\n");
Hello World
What's your name?
Alice
Hello Alice!
Most algorithms and data structures are tedious to write in languages such as Python, C or Java, while not being easy to reread. Algorab imports concepts from functional programming such as algebraic data types and pattern matching to make classic algorithmic problems clear and concise to describe.
enum LinkedList[A]:
case Empty
case Node(head: A, tail: LinkedList[A])
def append(element: A): LinkedList[A] = this match
case Empty then Node(head, Empty)
case Node(head, tail) then Node(head, tail.append(element))
class LinkedList:
def append(self, element):
pass
class Empty(LinkedList):
def append(self, element):
return Node(element, Empty())
class Node(LinkedList):
def __init__(self, head, tail):
self.head = head
self.tail = tail
def append(self, element):
return Node(self.head, self.tail.append(element))
#include <stdlib.h>
typedef struct Node {
int head;
struct Node *tail;
} LinkedList;
LinkedList *createNode(int head, LinkedList *tail) {
LinkedList *result = malloc(sizeof(LinkedList));
result->head = head;
result->tail = tail;
return result;
}
LinkedList *append(LinkedList *list, int element) {
if(list == NULL) return createNode(element, list);
else return createNode(list->head, append(list->tail, element));
}
Most programming languages do not provide the necessary tools for beginners to understand the issues they encounter, resulting in dropouts and times losses. Algorab has clear and precise error messages to help students understand and solve problems on their own.
record User(name: String, age: Int)
val user = User("John", 20)
println("Hello ${user.username} !")
Error: Unknown record field.
At ./myscript.algo, line 4, character 22
println("Hello ${user.username} !")
^^^^^^^^^^^^^
Hint: user is of type User.
Did you mean user.name?
Algorab encourages the use of good programming practices such as error handling, correct naming, adding comments and writing tests. With Algorab, students acquire skills that can be applied to the languages used in the professional world.
---
Create a new user.
- param name the user's name. Should not be empty.
- param age the user's age. Should be positive.
- return a new User with the given fields.
---
def createUser(name: String, age: Int): User can Throw[UserError] =
if name.isBlank then throw(UserError.BlankName)
else if age < 0 then throw(UserError.NegativeAge)
else User(name, age)
test createUser with
assertEquals(createUser("Sofia", 23), User("Sofia", 23))
assertThrows(createUser("", 23), UserError.BlankName)
assertThrows(createUser("Sofia", -23), UserError.NegativeAge)
Feature | ![]() | ![]() | Algorab |
---|---|---|---|
Strong static typing | |||
Meaningful error messages | |||
Expressivity | |||
Teaching good practices | |||
Rich ecosystem |
While some companies focus on maximising profitability, we have chosen to have a social impact. We are concerned about education and scientific research. Algorab is licensed under a free software licence, allowing anyone to use, study, modify and redistribute the project, promoting knowledge sharing and collaboration a sustainable future.
Algorab is still in development. The website will be edited as the project progresses and news will be sent to newsletter subscribers.