Realized that I cannot edit the original post, so I create a new topic. I apologize if this troubles you.
As a first step of my work on the Hi language, I want to collect feedback from the community, to see how many OCaml developers are interested in this language.
Below is a program that showcases a wide range of the Hi language’s features and capabilities. Though a fresh new language syntax, I guess most programmer are able to understand it. Note an extension is conceptually like an implicit module.
type Ordering = Less | Equal | Greater
type Ord a = (
compare : a -> a -> Ordering
)
data List a = Nil | Cons a (List a)
exception Empty
extension ListOps for List a {
fun head = match this with
| Cons x xs -> x
| Nil -> throw Empty
fun concat ys = match this with
| Nil -> ys
| Cons x xs -> Cons x (xs/.concat ys)
}
// Integers are orderable
extension OrdInt <: Ord Int {
fun compare x y = if x < y then Less
else if x == y then Equal
else Greater
}
extension SortList ?(ord: Ord a) for List a {
type This = List a
fun scan (compare: a -> Ordering) (xs: This) (less: This) (equal: This) (greater: This) = match xs with
| Nil -> (less, equal, greater)
| Cons y ys -> match compare y with
| Less -> scan compare (Cons y less) equal greater
| Equal -> scan compare less (Cons y equal) greater
| Greater -> scan compare less equal (Cons y greater)
fun sort = match this with
| Nil -> Nil
| Cons pivot ys -> {
val (less, equal, greater) = scan {x -> ord.compare x pivot} ys Nil (Cons pivot Nil) Nil
sort less /. concat equal /. concat (sort greater)
}
}
// Create a list of [2, 1, 4, 3].
val numbers = Cons 2 (Cons 1 (Cons 4 (Cons 3 Nil)))
val sorted = numbers /. sort
// Evaluate to Cons 1 (Cons 2 (Cons 3 (Cons 4 Nil))), representing [1, 2, 3, 4].
// Specify comparison function explicitly.
fun reverse order = match order with
| Less -> Greater
| Equal -> Equal
| Greater -> Less
val descOrd: Ord Int = (
compare = {a b ->
reverse (OrdInt.compare a b)
}
)
val descSort = (SortList ?descOrd).sort
val descNumbers = descSort numbers
// Evaluate to Cons 4 (Cons 3 (Cons 2 (Cons 1 Nil))), representing [4, 3, 2, 1].
Could you kindly vote below, so that I know the community’s interest and prioritize my work?
Question: if Hi language is available today, would you like to try it?
- Yes, I would like to try this new language.
- No, I don’t bother to try a new language.
0
voters
I really appreciate your vote and feedback, thanks!