Next Previous Contents

7. Standard DISs

Figure fig:dis gives the DIS functions that Green Card provides as a ``standard prelude''.

7.1 Haskell extensions

Several of the standard DISs involve types that go beyond standard Haskell:

7.2 Maybe

Almost all DISs work on single-constructor data types. It is much less obvious how to translate values of multi-constructor data types to and from C. Nevertheless, Green Card does deal in an ad hoc fashion with the Maybe type, because it seems so important. The syntax for the maybeT DIS is:

maybeT cexp dis

where dis is any DIS, and cexp is a C expression which represents the Nothing value in the C world.

In the following example, the function foo takes an argument of type Maybe Int. If the argument value is Nothing it will bind x to 0; if it is Just a it will bind x to the value of a. The return value will be Just r unless r == -1 in which case it will be Nothing.

%fun foo :: Maybe Int -> Maybe Int
%call (maybeT { 0 } (int x))
%code r = foo(x);
%result (maybeT { -1 } (int r))

There is also a maybe DIS wich just takes the DIS and defaults to 0 as the Nothing value.


Next Previous Contents