Carp/examples/sorting.carp

19 lines
534 B
Plaintext

(use Array)
(deftype Age [x Int])
;; TODO! Should be possible to use the IntRef implementation of = and < here but it resolves to the = in the Age module...
(defmodule Age
(defn = [a b]
(Int.= @(Age.x a) @(Age.x b)))
(defn > [a b]
(Int.> @(Age.x a) @(Age.x b)))
(defn < [a b]
(Int.< @(Age.x a) @(Age.x b))))
(defn main []
(let-do [ints (sort [10 3 75 40])
ages (sort [(Age.init 10) (Age.init 3) (Age.init 75) (Age.init 40)])]
(IO.println &(Array.str &ints))
(IO.println &(Array.str &ages))))