Thursday, March 17, 2022

Typed Egel

 Below, how Egel could look typed.  But I need something for software engineering in the large too, objects or modules or something. Mulling over that.

def fib: int -> int = [ 0 -> 1 | 1 -> 1 | | N -> N + fib (N - 1) + fib (N - 2) ]
type list[N] = nil | cons N list[N]
def concat: [N] => list[N] -> list[N] -> list[N] = [ nil YY -> YY | (cons X XX) YY -> cons X (concat XX YY) ] class ord N = def compare: N -> N -> int def less: N -> N -> bool instance ord int = def compare: int -> int -> int = int_compare def less: int -> int -> bool = int_less def sort: [ord N] => list[N] -> list[N] = [ nil -> nil | (cons X XX) -> insert X (sort XX) ] where def insert: [ord N] => N -> list[N] = [ X nil -> cons X nil | X (cons Y YY) -> if X < Y then cons X (cons Y YY) else cons Y (insert X YY) ]

No comments:

Post a Comment