Haskell and Maple FFI

Alastair Reid alastair at reid-consulting-uk.ltd.uk
Mon Sep 20 12:26:43 EDT 2004


> Examples ( taken from Open Maple )
>
>     ALGEB M_DECL MyStats( MKernelVector kv, ALGEB *args )
>     {
>         ALGEB mean, sd, f;
>
>         if( 1 != MapleNumArgs(kv,(ALGEB)args) ) {
>             MapleRaiseError(kv,"one argument expected");
>             return( NULL );
>         }
> ...
>         /* return the pair */
>         return( ToMapleExpressionSequence(kv,2,mean,sd) );
>     }
>
> Is it what do you mean ?

Yes, now use Haskell's ffi to import all those OpenMaple calls you made in the 
above.  That is, MapleNumArgs, ToMapleExpressionSequence, etc.

Having done that, translate the code into Haskell in the obvious way and check 
it works.

Try a range of examples, figure out what works and what doesn't work, figure 
out where the order of things matters and where it doesn't.

After you've done a bunch of examples, show us them and we can suggest how to 
use type classes to reduce most maple calls to just a line or two of Haskell 
code.

> I don't know on Marshalling/UnMarshalling...

Marshaling/unmarshalling is converting the argument list from Haskell (or, for 
that matter C) representation into Maple representation.  Half the code in 
your example was doing this.

--
Alastair Reid



More information about the FFI mailing list