shithub: mc

ref: 905f4d10a78e7e2f6eb849cf373b14cd78c87d73
dir: /test/trait-builtin.myr/

View raw version
use std
/* checks that generic types with traits are compiled correctly.
without the 'numeric' trait on '@a', the '>' operator would not work
within max. without the 'tctest' trait on '@a' in intlike_is42,
comparing to 42 wouldn't work.

exits with 42.
*/

generic max = {a : @a, b : @a :: numeric @a
	if a > b
		-> a
	else
		-> b
	;;
}

generic intlike_is42 = {a : @a :: numeric,integral @a
	-> a == 42
}

const main = {
	if intlike_is42(123)
	    std.exit(16)
	else
	    std.exit(max(12, 42))
	;;
}