// Eq, Ord, Show, Debug, Hash and Default for `()` and tuples (ADR 0018
// Rev. 1), from the prelude.
import std/io
@derive Eq Show Hash
pub type Point { Point(at: (Int, Int), label: String) }
fn same :: x: a y: a -> Bool where Eq
{
x == y
}
fn order :: o: Order -> String
{
match o { Lt -> "Lt", Eq -> "Eq", Gt -> "Gt" }
}
fn smallest :: xs: List best: a -> a where Ord
{
match xs
{ [] -> best, [x, ..rest] -> smallest rest if x < best { x } else { best } }
}
pub fn main :: -> () /
{
io.println (show () <> " " <> debug () <> " " <> show (() == ()))
io.println (show (1, "a") <> " " <> debug (1, "a"))
io.println (show ((1, 2) == (1, 2)) <> " " <> show ((1, 2) == (1, 3)))
io.println (show ((1, "b") < (1, "c")) <> " " <> show ((2, "a") > (1, "z")))
io.println (show (smallest [(2, "b"), (1, "z"), (2, "a")] (3, "")))
io.println
( show (hash (1, 2) == hash (1, 2)) <> " "
<> show (hash (1, 2) == hash (2, 1))
)
let zero: (Int, String, Bool) = default ()
io.println (debug zero)
io.println
( show (Point((1, 2), "p") == Point((1, 2), "p")) <> " "
<> show Point((1, 2), "p")
)
let done: Result<(), String> = Ok(())
io.println (show (same [("x", 1)] [("x", 1)]) <> " " <> show (done == Ok(())))
io.println (show (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12))
io.println
( order
( compare
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13)
)
)
}
//> () () True
//> (1, a) (1, "a")
//> True False
//> True True
//> (1, z)
//> True False
//> (0, "", False)
//> True Point((1, 2), p)
//> True True
//> (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
//> Lt