2015-11-13 15:49:00 -05:00
|
|
|
import io:*
|
2015-08-29 21:45:55 -04:00
|
|
|
|
|
|
|
|
adt options {
|
|
|
|
|
option0,
|
|
|
|
|
option1
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-06 03:23:55 -05:00
|
|
|
adt maybe_int {
|
|
|
|
|
no_int,
|
|
|
|
|
an_int: int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun handle_possibility(it: maybe_int) {
|
2015-11-09 13:26:02 -05:00
|
|
|
if (it == maybe_int::no_int()) {
|
2015-11-13 15:49:00 -05:00
|
|
|
println("no int")
|
2015-11-09 13:26:02 -05:00
|
|
|
}
|
2015-11-06 03:23:55 -05:00
|
|
|
/*if (it == maybe_int::an_int) {*/
|
|
|
|
|
else {
|
2015-11-13 15:49:00 -05:00
|
|
|
print("an int: ")
|
|
|
|
|
println(it.an_int)
|
2015-11-06 03:23:55 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun give_maybe(give_it: bool): maybe_int {
|
|
|
|
|
if (give_it)
|
|
|
|
|
return maybe_int::an_int(7)
|
|
|
|
|
return maybe_int::no_int()
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-30 01:53:11 -04:00
|
|
|
fun can_pass(it: options): options {
|
2015-11-06 03:23:55 -05:00
|
|
|
return it
|
2015-08-30 01:53:11 -04:00
|
|
|
}
|
|
|
|
|
|
2015-08-29 21:45:55 -04:00
|
|
|
fun main():int {
|
2015-11-06 03:23:55 -05:00
|
|
|
var it: options = can_pass(options::option0())
|
2015-11-09 13:26:02 -05:00
|
|
|
if (it == options::option0()) {
|
2015-11-13 15:49:00 -05:00
|
|
|
println("nope")
|
2015-11-09 13:26:02 -05:00
|
|
|
}
|
|
|
|
|
if (it == options::option1()) {
|
2015-11-13 15:49:00 -05:00
|
|
|
println("option1")
|
2015-11-09 13:26:02 -05:00
|
|
|
}
|
2015-11-06 03:23:55 -05:00
|
|
|
|
|
|
|
|
var possibility = give_maybe(false)
|
|
|
|
|
handle_possibility(possibility)
|
|
|
|
|
possibility = give_maybe(true)
|
|
|
|
|
handle_possibility(possibility)
|
2015-11-13 15:49:00 -05:00
|
|
|
if ( maybe_int::an_int(7) == maybe_int::an_int(7) )
|
|
|
|
|
println("equality true works!")
|
|
|
|
|
else
|
|
|
|
|
println("equality true fails!")
|
|
|
|
|
|
|
|
|
|
if ( maybe_int::an_int(7) != maybe_int::an_int(8) )
|
|
|
|
|
println("equality false works!")
|
|
|
|
|
else
|
|
|
|
|
println("equality false fails!")
|
2015-11-14 19:05:28 -05:00
|
|
|
|
|
|
|
|
match (maybe_int::an_int(11)) {
|
|
|
|
|
maybe_int::an_int(the_int) {
|
|
|
|
|
print("matched an int:")
|
|
|
|
|
print(the_int)
|
|
|
|
|
println(" correctly!")
|
|
|
|
|
}
|
|
|
|
|
maybe_int::no_int() {
|
|
|
|
|
println("matched no int incorrectly!")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
match (maybe_int::no_int()) {
|
|
|
|
|
maybe_int::an_int(the_int) println("matched an int incorrectly!")
|
|
|
|
|
maybe_int::no_int() println("matched no int correctly!")
|
|
|
|
|
}
|
2015-08-29 21:45:55 -04:00
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|