old-language.mty (2502B)
ns main;
from namespace use stream_data;
let Point :: x:f, y:f;
let Player :: {
pos:Point;
health:f;
age:i;
fx distance : Player -> (f, f) :: (abs(Player.pos.x - pos.x), abs(Player.pos.y - pos.y));
}
fx distance p1:Player, p2:Player -> f, f ::
(abs(p1.pos.x - p2.pos.x), abs(p1.pos.y - p2.pos.y));
pub dupe :: (str, int) = (*)
let Player :: struct {
Point pos;
dec health;
int age;
bool alive;
pub is_old = age > 60;
}
let RSVP :: enum(str) {
}
enum(str) RSVP :: YES, NO;
pub struct Person ::
str name,
str domain,
int age,
dec size,
Bool alive,
RSVP invited,
fx is_alive :: -> bool = .alive,
fn email :: -> str = "$name@${domain}",
fx knows :: Person p -> bool = .in_contact_with(p);
fx new_external_person :: str name -> Person = Person(name: name, alive: true);
fx(Float, Float) distance(Point a, b) :: (abs(a.x - b.x), abs(a.y - b.y))
fx distance :: Point a, b -> Float, Float = (abs(a.x - b.x), abs(a.y - b.y));
let Person :: struct = str name, int age, dec size, bool alive, RSVP invite;
fx in_space :: char c -> bool = (c == ' ' || c == '\r' || c == '\n' || c == '\t');
fx rev :: str x -> str = x[.. by -1];
fx trim :: str x -> str = x
| x[drop while in_space]
| rev
| x[drop while in_space]
| rev;
fx say_hello() :: printf("hello\n")
fx distance(Point a, b) ::
(abs(a.x - b.x), abs(a.y - b.y))
fx distance(Point a, b -> (dec, dec))
fx is_even(ref int -> bool) = (% 2 == 0)
fx distance(Point a, b) -> (f, f) = (abs(a.x - b.x), abs(a.y - b.y))
----------
fx distance(a:pos, b:pos) (f, f) = (abs(a.x - b.x), abs(a.y - b.y))
let Player = {
pos:Point,
health:f,
age:i,
alive:b = true
fx distance :: fx(p2:Player) (f, f) = (abs(pos.x - p2.pos.x), abs(pos.y - p2.pos.y))
}
let even : i -> b :: % 2 == 0
let add : i, i -> i :: +
let add_mult_by_5 : i, i -> i :: + * 5
let add_mult_by_6 : a:i, b:i -> i :: (a + b) * 6
fx add_mult_by_x (a:i, b:i, x:i) i = (a + b) * x
from libc use printf[ffi]
fx say_hello :: printf("hello\n")
fx say_hello = printf("hello\n")
fx rev(text:s) -> s = text[.. by -1];
fx rev :
s -> s = s[.. by -1]
fn is_space : c -> b =
c == ' ' || c == '\r' || c == '\n' || c == '\t';
fx trim(text:s) -> s =
len(text) == 0 ? text :
text
| t => t[drop while is_space]
| rev
| t => t[drop while is_space]
| rev;
is_space :: c -> b = c == ' ' || c == '\r' || c == '\n' || c == '\t';
pub let is_space : c -> b = (c == ' ' || c == '\r' || c == '\n' || c == '\t');
is_space :: char c -> bool =