MLscript is a programming language created in 2020 by Luyu Cheng and Lionel Parreaux.
#1043on PLDB | 4Years Old |
git clone https://github.com/hkust-taco/mlscript/
A step towards rethinking pattern matching to make it more powerful and natural to use.
type List[A] = Cons[A] | Nil
class Cons[out A](head: A, tail: List[A]) {
fun map: (A -> 'B) -> List['B]
map(f) = Cons of f(head), tail.map(f)
}
module Nil {
fun map(f) = Nil
}
fun (::) cons(x, xs) = Cons(x, xs)
fun show(xs) =
let rec go(xs) = if xs is
Cons(h, Nil) then String(h)
Cons(h, t) then join(String(h), ", ", go(t))
Nil then ""
join("[", go(xs), "]")
let xs = 1 :: 2 :: 3 :: Nil
show(xs)
show(xs.map of x => succ(x))