2010-06-28 23:18:51 -07:00
|
|
|
type option[T] = tag(none(), some(T));
|
|
|
|
|
|
2010-07-05 14:36:39 -07:00
|
|
|
type operator[T, U] = fn(&T) -> U;
|
2010-06-28 23:18:51 -07:00
|
|
|
|
2010-07-05 14:36:39 -07:00
|
|
|
fn option_map[T, U](&operator[T, U] f, &option[T] opt) -> option[U] {
|
2010-06-28 23:18:51 -07:00
|
|
|
alt (opt) {
|
|
|
|
|
case (some[T](x)) {
|
|
|
|
|
ret some[U](f[T, U](x));
|
|
|
|
|
}
|
|
|
|
|
case (none[T]()) {
|
|
|
|
|
ret none[U]();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn id[T](T x) -> T {
|
|
|
|
|
ret x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type rational = rec(int num, int den);
|