packages feed

mathlink-2.0.0.7: example/README

A script for a Mathematica session using the example package:


1. Install the mathlink library.


2. cd into the example/ directory and build the executable:

   > ghc --make Test.hs


3. Start Mathematica and install the package, e.g.:

   lnk = Install["~/hs/mathlink/example/Test"]

   Out[_]:= LinkObject["/home/twadleigh/hs/mathlink/example/Test", 5, 5]


4. Show the public symbols in the newly added package:

   ?Test`*

   You should see something like:

   Test`*
   Ackermann        AddFour


5. Call the Ackermann function:

   Ackermann[4,1]

   Out[_]:= 65553


6. The marshaling can handle arbitrarily sized integers:

   Ackermann[4,2]

   Out[_]:= 2003529930406846464979072351...

   Marshaling of unbounded integers is accomplished via strings.


7. The function calls should respond immediately to an abort request.
   Start a computation running by entering:

   Ackermann[4,3]

   then press Alt+. to attempt to abort. You should immediately get:

   Out[_]:= $Aborted.


8. Exceptions uncaught in the execution of the Haskell function are
   caught by library code, and a message is sent to Mathematica. 
   E.g., run:

   Ackermann[4,3]

   again, but this time wait a little bit. You should eventually see:

   MathLink::exn : Exception caught: stack overflow
   Out[_]:= $Failed

   Of course, the stack overflow problem can generally be mitigaged
   by passing appropriate flags to the GHC runtime. One way to make 
   doing this work nicely with Mathematica is to write a script that 
   passes the desired RTS flags along with those given on the command 
   line. See the test.sh script in this directory for an example.
  
9. Uninstall the package:

   Uninstall[lnk]

   Out[_]:= "/home/twadleigh/hs/mathlink/example/Main"