PreviousUpNext

14.2.29  Null_Or

The standard library Null_Or api defines access to optional-value functionality.

The Null_Or api is implemented by the null_or package.

The Null_Or api source code is in src/lib/std/src/null-or.api.

The above information is manually maintained and may contain errors.

api {
    Null_Or X = NULL | THE X;
    exception NULL_OR;
    the_else : (Null_Or(X ) , X) -> X;
    not_null : Null_Or(X ) -> Bool;
    the : Null_Or(X ) -> X;
    filter : (X -> Bool) -> X -> Null_Or(X );
    join : Null_Or(Null_Or(X ) ) -> Null_Or(X );
    apply : (X -> Void) -> Null_Or(X ) -> Void;
    map : (X -> Y) -> Null_Or(X ) -> Null_Or(Y );
    map' : (X -> Null_Or(Y )) -> Null_Or(X ) -> Null_Or(Y );
    compose : ((X -> Z) , (Y -> Null_Or(X ))) -> Y -> Null_Or(Z );
    compose_partial : ((X -> Null_Or(Z )) , (Y -> Null_Or(X ))) -> Y -> Null_Or(Z );};

The following information is manually maintained and may contain errors. Mythryl’s Null_Or facility corresponds closely to the C/C++ NULL pointer facility. The critical difference is that C/C++ programs can and do crash at runtime when the code attempts to dereference a NULL pointer, whereas in Mythryl static compile-time checking guarantees that this can never happen.

A type Foo is converted to one which also allows NULL values via the Null_Or type function: Null_Or( Foo ).

Mythryl type-checking then requires that values of this type always be checked for NULL values before being used in a computation, typically via code like

    fun print_string  (maybe_string: Null_Or( String ))
 =
 case (maybe_string)
 NULL => ();
 string => printf ``Your string is '%s'.'' string;
 esac;

Comments and suggestions to: bugs@mythryl.org

PreviousUpNext