summaryrefslogtreecommitdiff
path: root/test/trait-builtin.myr
blob: ba7034bfc7c51f555cdc00f2247ae195cc0567c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* checks that generic types with traits are compiled correctly.
without the 'tcnum' 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::tcnum, b:@a::tcnum
	if a > b
		-> a
	else
		-> b
	;;
}

generic intlike_is42 = {a : @a::(tcnum,tctest,tcint)
	-> a == 42
}
const main = {
	if intlike_is42(123)
	    -> 16
	else
	    -> max(12, 42)
	;;
}