next up previous index
Next: Control structures Up: Basic data types and Previous: Object aggregation   Index

Options

In maybe.cecil:

abstract object maybe[`T];
extend type maybe[`T] subtypes maybe[`S >= T];
  signature if_some_none(maybe[`T], if_some:&(T):`T1, if_none:&():`T2):T1|T2;
  method if_some(m@:maybe[`T], if_some:&(T):void):void;
  method if_none(m@:maybe[`T], if_none:&():void):void;
  method is_some(m@:maybe[`T]):bool;
  method is_none(m@:maybe[`T]):bool;
  signature value(maybe[`T]):T;
  method value(m@:maybe[`T1], if_none:&():`T2):T1|T2;
template object some[`T] isa maybe[T];
extend type some[`T] subtypes some[`S >= T];
  field value(@:some[`T]):T;
  method if_some_none(s@:some[`T], if_some:&(T):`T1, if_none:&():`T2):T1|T2;
  method some(value:`T):some[T];
  method some[`T](value:T):some[T];
  method print_string(s@:some[`T]):string;
concrete object none[`T] isa maybe[T];
extend type none[`T] subtypes none[`S >= T];
  method if_some_none(@:none[`T], if_some:&(T):`T1, if_none:&():`T2):T1|T2;
  method value(@:none[`T]):T;
extend object maybe[`T <= comparable[T]] isa comparable[maybe[T]];
  method =(@:maybe[`T <= comparable[T]], @:maybe[`T]):bool;
  method =(s1@:some[`T <= comparable[T]], s2@:some[`T]):bool;
  method =(@:none[`T <= comparable[T]], @:none[`T]):bool;
extend object maybe[`T <= hashable[T]] isa hashable[maybe[T]];
  method hash(s@:some[`T <= hashable[T]], range:int):int;
  method hash(@:none[`T <= hashable[T]], range:int):int;
The maybe[T] parameterized type represents either a value of type T or no value, akin to ML's option datatype. maybes are useful where an explicit null pointer might be used in some other language, but the possibility for null is explicit when using maybes.


next up previous index
Next: Control structures Up: Basic data types and Previous: Object aggregation   Index

The Cecil project