Skip to content

elisiei/hml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Holy ML, WIP

arregla el puto ssh elisiei subnormal cómo voy a adivinar que el puerto ssh es el puto 22222? Acaso soy adivino?

features

basic primitives

(* Primitive types *)
byte    bits32  bits64  bits128
ubyte   ubits32 ubits64 ubits128
float32 float64 bool

int    (* alias to 'bits64' *)
float  (* alias to 'float64' *)
number (* arbitrary length *)
string (* same as `u8 array` *)

(* Product types *)
type vec3 = { x: float; y: float; z: float }

immutability by default

(* mutability *)
let counter : int ref = ref 1

(* syntax sugar *)
let add a b = a+b

(* de-sugared *)
let add = fun a b -> a+b

(* even more de-sugared *)
let add = fun b -> fun b -> a+b

structs

type 'a some = { value : 'a }
type none = { }

bare unions (union)

union option = {
    some : 'a some
    none : none
}

ADTs

type 'a adt_option =
    | 'a some
    | none

ADTs sugar (data)

data 'a option =
    | Some of 'a
    | None

structs are tuples

type person = {
    age : int
    name : u8 array
}
let my_person = person 16 "yuzu"
let my_tuple  = (16, "yuzu")

no IO monad

external read_file (path : string) : string = "read_file"
external print (s : string) : unit          = "puts"

let greet () =
  let name = read_file "name.txt" in
  print ("Hello, " .. name)

operations on structs

type particle = {
  position : vec3
  velocity : vec3
}

(* gets the alignment of particle *)
alignof particle

(* gets the typeof particle *)
typeof particle

(* may also be packed *)
@packed
type particle = {
  position : vec3
  velocity : vec3
}

(* stack-only allocation *)
@stack
type particle = {
  position : vec3
  velocity : vec3
}

struct of arrays by default

(* optimizes it as a struct of arrays layout *)
@soa
type entity = {
  position: vec3;
  velocity: vec3;
  health: float;
}

(* effectively it becomes: *)
type entity {
    cap        : int
    len        : int
    positions  : vec3 ptr
    velocities : vec3 ptr
    healths    : float ptr (* TODO: this is only possible with void pointers LOL *)
}

(* works with bare unions *)
(* it is a way more effective design than allocating ADTs *)
@soa
union animal = {
    koala   : Koala
    jiraffe : Jiraffe
}

(* effectively it becomes *)
enum animal_type = {
    koala
    jiraffe
}
union animal_data = {
    koala   : Koala
    jiraffe : Jiraffe
}
type animals = {
    data  : animal_data array
    types : animal_type array
}

pattern matching

let area s =
    match s with
    | Circle { radius } -> Math.pi *. radius *. radius
    | Rect { width; height } -> width *. height

modules

module Physics = struct
    @private (* everything is public by default *)
    let gravity = 9.81

    let apply_force mass acceleration =
    mass *. acceleration
end

TODO:

modules

just as OCaml

exceptions

just as OCaml

public and private fields

no need, everything is public

manual memory management

with custom allocators if possible

About

by yuzucchii.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published