Haskell and Maple FFI
alastair at reid-consulting-uk.ltd.uk
Fri Sep 17 04:54:05 EDT 2004
> I would like to implement a new "calling convention" for Maple
> language, so that programers in Haskell may call for Maple routines.
> Both languages are intereseting for cooperation, due to its symbolic
Making it possible to call Maple would be very cool. Can you give more detail
about Open Maple?
If I was doing this, I'd start by writing some C code that interfaces to
Maple. After that works, I'd translate it into Haskell. That is, I would
use the FFI to invoke the Maple FFI functions for pushing arguments, popping
results, etc. and use the the FFI libraries which have lots of useful
functions for marshaling arguments from Haskell to other formats.
Start with something simple (e.g., a single argument function like 'sin'),
prototype in C, translate to Haskell. At this point, don't worry too much
about the fact that the simplest function call seems to require 10-20 lines
of code - we can suggest ways to fix that. Keep trying new features (2
arguments, strings, calling both Haskell->Maple and Maple->Haskell, etc.)
[The Open Maple manual probably has a list of examples used to illustrate the
interface - start by doing all those.] If it isn't obvious how to do it or
it just won't work, step back and write a prototype in C.
Ask us as you run into problems.
Once you can do all that, there's a bunch of tricks you can play with
typeclasses to reduce the number of lines of code you have to write from
10-20 lines down to just one or two. (Ross Paterson has a very nice scheme
for doing this - but I can't find it in the mail archives at the moment.)
More information about the FFI