packages feed

mathlink 1.0.0.1 → 1.1.0.0

raw patch · 5 files changed

+117/−330 lines, 5 files

Files

examples/mltest.nb view
@@ -10,41 +10,32 @@ NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[       145,          7]-NotebookDataLength[     12759,        344]-NotebookOptionsPosition[     11283,        286]-NotebookOutlinePosition[     11641,        302]-CellTagsIndexPosition[     11598,        299]+NotebookDataLength[      4548,        134]+NotebookOptionsPosition[      3912,        110]+NotebookOutlinePosition[      4270,        126]+CellTagsIndexPosition[      4227,        123] WindowFrame->Normal*)  (* Beginning of Notebook Content *) Notebook[{--Cell[CellGroupData[{ Cell[BoxData[  RowBox[{"SetDirectory", "[", "\"\<~/hs/mathlink/examples/\>\"",    "]"}]], "Input",  CellChangeTimes->{{3.439309979806336*^9, 3.439310029119624*^9}, {   3.439504790090583*^9, 3.439504790564527*^9}}], -Cell[BoxData["\<\"/home/twadleigh/hs/mathlink/examples\"\>"], "Output",- CellChangeTimes->{{3.439504769908993*^9, 3.439504791247632*^9}, -   3.440168667032764*^9, 3.440177535376698*^9, 3.4401803149179897`*^9, -   3.4413812970022373`*^9, 3.441491000419338*^9}]-}, Open  ]],- Cell[TextData[{  "Wrapping the ",  StyleBox["MathLink",   FontSlant->"Italic"],  " executable in a shell script is a nice way to pass extra arguments to the \-GHC RTS without interferring with the command line arguments that ",+GHC RTS without interfering with the command line arguments that ",  StyleBox["MathLink",   FontSlant->"Italic"],  " needs to pass to establish the connection." }], "Text",- CellChangeTimes->{{3.440168766081661*^9, 3.440168924034021*^9}}],--Cell[CellGroupData[{+ CellChangeTimes->{{3.440168766081661*^9, 3.440168924034021*^9}, +   3.442004040708877*^9}],  Cell[BoxData[  RowBox[{"lnk", "=", @@ -54,41 +45,10 @@   3.439313786830782*^9}, {3.439314248568095*^9, 3.439314249330996*^9}}],  Cell[BoxData[- RowBox[{"LinkObject", "[", -  RowBox[{"\<\"/home/twadleigh/hs/mathlink/examples/mltest.sh\"\>", ",", -   "3897", ",", "9"}], "]"}]], "Output",- CellChangeTimes->{-  3.4413816897789*^9, 3.441381776726746*^9, 3.441381863003125*^9, -   3.441382755890881*^9, 3.441383611414963*^9, 3.4413837695712976`*^9, -   3.441384211503524*^9, 3.441385803766169*^9, 3.441386080695139*^9, -   3.441387244598215*^9, 3.441387779567708*^9, {3.441387949000835*^9, -   3.441387976609853*^9}, 3.44138846489312*^9, 3.4413885012431507`*^9, -   3.441388550071382*^9, 3.4413906521514463`*^9, 3.441418693983523*^9, -   3.4414188494746513`*^9, 3.441491002436418*^9}]-}, Open  ]],--Cell[CellGroupData[{--Cell[BoxData[  RowBox[{"AddTwo", "[",    RowBox[{"2", ",", "3"}], "]"}]], "Input",  CellChangeTimes->{{3.43931006947751*^9, 3.43931007209233*^9}}], -Cell[BoxData["5"], "Output",- CellChangeTimes->{-  3.44016867170964*^9, 3.4401775395852757`*^9, 3.440177642067905*^9, -   3.440177770296537*^9, 3.440178013081019*^9, 3.440180318765966*^9, -   3.440261706988338*^9, 3.440262267330207*^9, 3.44026304258245*^9, -   3.4402641219488163`*^9, 3.4402642658697*^9, {3.4402644178146067`*^9, -   3.4402644191880302`*^9}, 3.4413813057112007`*^9, 3.441381441541993*^9, -   3.441383613208295*^9, 3.441383771554179*^9, 3.4413842134637823`*^9, -   3.441385806201159*^9, 3.441387246470428*^9, 3.441387781194582*^9, {-   3.441387950532065*^9, 3.441387978232432*^9}, 3.441388469306093*^9, -   3.4413906541514683`*^9, 3.441418696364647*^9, 3.441491004440143*^9}]-}, Open  ]],--Cell[CellGroupData[{- Cell[BoxData[  RowBox[{"ReverseNumbers", "[",    RowBox[{@@ -98,49 +58,6 @@   3.440180321606152*^9, 3.440180358834758*^9}}],  Cell[BoxData[- RowBox[{"{", -  RowBox[{-  "3.141592653589793`", ",", "2.718281828459045`", ",", "0.`", ",", "3.`", -   ",", "2.`", ",", "1.`"}], "}"}]], "Output",- CellChangeTimes->{-  3.440168712981926*^9, 3.440177541747458*^9, 3.4401776436073923`*^9, -   3.440177771845735*^9, 3.4401780146157618`*^9, {3.440180323067984*^9, -   3.440180359740733*^9}, 3.440261709575554*^9, 3.4402630445039377`*^9, -   3.440264267960457*^9, 3.440264420978492*^9, 3.441381307968505*^9, -   3.441381443541602*^9, 3.441383773992701*^9, 3.44138421533407*^9, -   3.441385807884037*^9, 3.4413872484380293`*^9, 3.441387979824582*^9, -   3.4413884893522873`*^9, 3.441390659007481*^9, 3.441418698597937*^9, -   3.4414910070039387`*^9}]-}, Open  ]],--Cell[CellGroupData[{--Cell[BoxData[- RowBox[{"GreetWorld", "[", "]"}]], "Input",- CellChangeTimes->{{3.440168718131279*^9, 3.4401687204719067`*^9}}],--Cell[BoxData[- RowBox[{"{", -  RowBox[{-   RowBox[{"{", -    RowBox[{"\<\"H\"\>", ",", "\<\"e\"\>", ",", "\<\"l\"\>", ",", "\<\"l\"\>",-      ",", "\<\"o\"\>", ",", "\<\",\"\>", ",", "\<\" \"\>", ",", "\<\"w\"\>", -     ",", "\<\"o\"\>", ",", "\<\"r\"\>", ",", "\<\"l\"\>", ",", "\<\"d\"\>", -     ",", "\<\"!\"\>"}], "}"}], ",", "\<\"Hello, world!\"\>"}], -  "}"}]], "Output",- CellChangeTimes->{-  3.4401687210248337`*^9, 3.440177543338463*^9, 3.4401776462215652`*^9, -   3.440177773588876*^9, 3.440178015619836*^9, 3.440180378796352*^9, -   3.4402617123528633`*^9, 3.4402630465175877`*^9, {3.440264269597514*^9, -   3.440264271412078*^9}, 3.4402644226770697`*^9, 3.44138130986276*^9, -   3.441381445073922*^9, 3.441383777014336*^9, 3.441384217030814*^9, -   3.4413858094822197`*^9, 3.441387249965949*^9, 3.4414187007709637`*^9, -   3.441491009312787*^9}]-}, Open  ]],--Cell[CellGroupData[{--Cell[BoxData[  RowBox[{"ReverseArray", "[",    RowBox[{"{",     RowBox[{@@ -151,29 +68,6 @@  CellChangeTimes->{{3.440168935664534*^9, 3.440168948360408*^9}}],  Cell[BoxData[- RowBox[{"{", -  RowBox[{-   RowBox[{"{", -    RowBox[{-     RowBox[{"{", "1", "}"}], ",", -     RowBox[{"{", "2", "}"}], ",", -     RowBox[{"{", "3", "}"}]}], "}"}], ",", -   RowBox[{"{", -    RowBox[{-     RowBox[{"{", "4", "}"}], ",", -     RowBox[{"{", "5", "}"}], ",", -     RowBox[{"{", "6", "}"}]}], "}"}]}], "}"}]], "Output",- CellChangeTimes->{3.440168948815699*^9, 3.4401775454085293`*^9, -  3.440177647824188*^9, 3.4401777759225273`*^9, 3.440178017618819*^9, -  3.4401803839453077`*^9, 3.4402617143337603`*^9, 3.4402630480736322`*^9, -  3.440264274052725*^9, 3.440264424466619*^9, 3.441381351458521*^9, -  3.441381449711451*^9, 3.4413837789184637`*^9, 3.4413842200390663`*^9, -  3.441387251527453*^9, 3.441418703279256*^9, 3.441491011027935*^9}]-}, Open  ]],--Cell[CellGroupData[{--Cell[BoxData[  RowBox[{"TweakExpression", "[",    RowBox[{"{",     RowBox[{"ASymbol", ",", "\"\<A string\>\"", ",", "3", ",", @@ -184,24 +78,6 @@   3.440177845556456*^9}, {3.440178025829589*^9, 3.440178050101166*^9}}],  Cell[BoxData[- RowBox[{"tsiL", "[", -  RowBox[{"lobmySA", ",", "\<\"gnirts A\"\>", ",", -   RowBox[{"-", "3"}], ",", -   RowBox[{"-", "3.141592653589793`"}], ",", -   RowBox[{"sulP", "[", -    RowBox[{"a", ",", "b", ",", "c"}], "]"}]}], "]"}]], "Output",- CellChangeTimes->{-  3.4401777251469917`*^9, 3.440177777974738*^9, 3.4401778462290287`*^9, {-   3.4401780196886597`*^9, 3.440178050944537*^9}, 3.440180387144931*^9, -   3.440261716956626*^9, 3.440263049754879*^9, 3.440264276797727*^9, -   3.440264426317778*^9, 3.441381360007936*^9, 3.441381452206236*^9, -   3.441383780806993*^9, 3.441384222446288*^9, 3.4413872531264553`*^9, -   3.441418705414536*^9, 3.441491013393704*^9}]-}, Open  ]],--Cell[CellGroupData[{--Cell[BoxData[  RowBox[{"AddExtendedComplexes", "[",    RowBox[{    RowBox[{"1", "+", @@ -213,20 +89,6 @@   3.44026232761686*^9}, {3.440264128954616*^9, 3.440264134710162*^9}}],  Cell[BoxData[- RowBox[{"3.`", "\[InvisibleSpace]", "+", -  RowBox[{"8.`", " ", "\[ImaginaryI]"}]}]], "Output",- CellChangeTimes->{-  3.4402617532268353`*^9, {3.440261864732419*^9, 3.440261871312593*^9}, -   3.440262143838559*^9, 3.4402622723110037`*^9, 3.440262328404337*^9, -   3.440263051601795*^9, 3.4402641351875563`*^9, 3.4402642789828243`*^9, -   3.4402644285115223`*^9, 3.441381455911284*^9, 3.44138378263803*^9, -   3.441384224886664*^9, 3.44138725472222*^9, 3.441418706707465*^9, -   3.441491015262816*^9}]-}, Open  ]],--Cell[CellGroupData[{--Cell[BoxData[  RowBox[{"AddExtendedComplexes", "[",    RowBox[{"Infinity", ",",     RowBox[{"1", "+", @@ -235,16 +97,6 @@   3.440262468823717*^9, 3.440262473845871*^9}, {3.440264138208585*^9,    3.440264140343564*^9}}], -Cell[BoxData["\[Infinity]"], "Output",- CellChangeTimes->{3.440262345780912*^9, 3.44026247434591*^9, -  3.440263054136756*^9, 3.440264140800539*^9, 3.4402642809102592`*^9, -  3.440264430358942*^9, 3.4413814578432207`*^9, 3.441383783897023*^9, -  3.4413842262926207`*^9, 3.4413860855117683`*^9, 3.4413872565223503`*^9, -  3.441418707827199*^9, 3.4414910169835653`*^9}]-}, Open  ]],--Cell[CellGroupData[{- Cell[BoxData[  RowBox[{"AbortTest", "[", "50", "]"}]], "Input",  CellChangeTimes->{{3.4413814839615593`*^9, 3.44138148687442*^9}, {@@ -252,37 +104,9 @@   3.441386092152405*^9}, {3.441387279931728*^9, 3.4413872801019363`*^9}, {   3.4414187331544437`*^9, 3.4414187357368517`*^9}}], -Cell[BoxData["True"], "Output",- CellChangeTimes->{-  3.441381487619445*^9, 3.44138169978981*^9, 3.441381782395792*^9, {-   3.441381905687695*^9, 3.441381921320157*^9}, 3.4413827674143963`*^9, -   3.441383632073021*^9, 3.441384195206551*^9, {3.441385787032784*^9, -   3.441385825540018*^9}, {3.441386088582046*^9, 3.441386093667964*^9}, {-   3.441387258934795*^9, 3.441387288148602*^9}, {3.4413877897953033`*^9, -   3.441387795451263*^9}, {3.441388512784028*^9, 3.4413885577855253`*^9}, {-   3.44139066804643*^9, 3.4413906737232437`*^9}, {3.4414187117340508`*^9, -   3.44141874145138*^9}, {3.4414910241849747`*^9, 3.441491033597106*^9}}]-}, Open  ]],--Cell[CellGroupData[{- Cell[BoxData[  RowBox[{"Uninstall", "[", "lnk", "]"}]], "Input",- CellChangeTimes->{{3.439313773653487*^9, 3.439313777607768*^9}}],--Cell[BoxData["\<\"/home/twadleigh/hs/mathlink/examples/mltest.sh\"\>"], \-"Output",- CellChangeTimes->{-  3.440168967229312*^9, 3.440177561117154*^9, 3.440177755031232*^9, -   3.440177984565681*^9, 3.4401780921022263`*^9, 3.440180388638576*^9, -   3.440261841211409*^9, {3.440264295025028*^9, 3.44026429805313*^9}, -   3.440264432207209*^9, 3.441381406035787*^9, {3.441381675639502*^9, -   3.441381704566267*^9}, 3.4413818574534807`*^9, 3.441382750107748*^9, -   3.441383567485149*^9, 3.44138579638888*^9, 3.4413860740598707`*^9, -   3.441387237789958*^9, 3.441387763869083*^9, {3.441387944051606*^9, -   3.441387958012869*^9}, 3.441390784907803*^9, 3.441418824055894*^9, -   3.441418861733427*^9, 3.4414910414708023`*^9}]-}, Open  ]]+ CellChangeTimes->{{3.439313773653487*^9, 3.439313777607768*^9}}] }, WindowSize->{1916, 1165}, WindowMargins->{{0, Automatic}, {4, Automatic}},@@ -301,51 +125,17 @@ *) (*NotebookFileOutline Notebook[{-Cell[CellGroupData[{-Cell[567, 22, 213, 4, 88, "Input"],-Cell[783, 28, 259, 3, 88, "Output"]-}, Open  ]],-Cell[1057, 34, 398, 10, 96, "Text"],-Cell[CellGroupData[{-Cell[1480, 48, 315, 5, 88, "Input"],-Cell[1798, 55, 651, 11, 88, "Output"]-}, Open  ]],-Cell[CellGroupData[{-Cell[2486, 71, 146, 3, 88, "Input"],-Cell[2635, 76, 691, 10, 88, "Output"]-}, Open  ]],-Cell[CellGroupData[{-Cell[3363, 91, 284, 6, 88, "Input"],-Cell[3650, 99, 710, 13, 88, "Output"]-}, Open  ]],-Cell[CellGroupData[{-Cell[4397, 117, 126, 2, 88, "Input"],-Cell[4526, 121, 857, 16, 88, "Output"]-}, Open  ]],-Cell[CellGroupData[{-Cell[5420, 142, 300, 8, 88, "Input"],-Cell[5723, 152, 770, 18, 88, "Output"]-}, Open  ]],-Cell[CellGroupData[{-Cell[6530, 175, 444, 8, 88, "Input"],-Cell[6977, 185, 681, 13, 88, "Output"]-}, Open  ]],-Cell[CellGroupData[{-Cell[7695, 203, 418, 9, 88, "Input"],-Cell[8116, 214, 515, 9, 88, "Output"]-}, Open  ]],-Cell[CellGroupData[{-Cell[8668, 228, 327, 7, 88, "Input"],-Cell[8998, 237, 367, 5, 88, "Output"]-}, Open  ]],-Cell[CellGroupData[{-Cell[9402, 247, 333, 5, 88, "Input"],-Cell[9738, 254, 637, 9, 88, "Output"]-}, Open  ]],-Cell[CellGroupData[{-Cell[10412, 268, 130, 2, 88, "Input"],-Cell[10545, 272, 722, 11, 88, "Output"]-}, Open  ]]+Cell[545, 20, 213, 4, 61, "Input"],+Cell[761, 26, 423, 11, 96, "Text"],+Cell[1187, 39, 315, 5, 61, "Input"],+Cell[1505, 46, 146, 3, 61, "Input"],+Cell[1654, 51, 284, 6, 61, "Input"],+Cell[1941, 59, 300, 8, 61, "Input"],+Cell[2244, 69, 444, 8, 61, "Input"],+Cell[2691, 79, 418, 9, 61, "Input"],+Cell[3112, 90, 327, 7, 61, "Input"],+Cell[3442, 99, 333, 5, 88, "Input"],+Cell[3778, 106, 130, 2, 88, "Input"] } ] *)
examples/src/Main.hs view
@@ -1,15 +1,12 @@ {-# OPTIONS_GHC -O #-} {- The -O option is necessary to get the rewrite rules which use more-   efficient marshaling for certain structured types to fire. According-   to the GHC documentation, it should be sufficient to set-   -fenable-rewrite-rules, but this didn't work in the test cases I-   examined, while -O (which implies -fenable-rewrite-rules) did. +   efficient marshaling for certain structured types to fire.  -}  module Main where  import Foreign.MathLink-import qualified Foreign.MathLink.Expressible as Ex+import Foreign.MathLink.Expressible  import Data.Array.Unboxed import Data.Complex@@ -18,145 +15,114 @@ import System.Timeout  -- Example 1: get a pair of integers and return their sum.-addTwo :: IO ()-addTwo = do-  (m1,m2) <- get-  put ((m1 + m2) :: Int)+addTwo :: (Int,Int) -> IO Int+addTwo (m1,m2) = return (m1+m2) --- callPattern <=> mprep's :Pattern: directive--- argumentPattern <=> mprep's :Arguments: directive--- Note that, in argumentPattern, the desired 2-tuple of integers--- is represented as a Mathematica list of length 2.-addTwoFunction = -  Function { callPattern = "AddTwo[i_Integer,j_Integer]"-           , argumentPattern = "{i,j}"-           , function = addTwo-           }+-- Note that the desired 2-tuple of integers is represented as +-- a Mathematica list of length 2.+addTwoFunction = mkFunction -- mprep's :Pattern: directive+                            "AddTwo[i_Integer,j_Integer]"+                            -- mprep's :Arguments: directive+                            "{i,j}"+                            addTwo  -- Example 2: reverse a list of numbers (coercing them to Doubles).-reverseNumbers :: IO ()-reverseNumbers = do-  is <- get-  put $ reverse (is :: [Double])+reverseNumbers :: [Double] -> IO [Double]+reverseNumbers is = return $ reverse is  -- Like tuples, lists are represented on the Mathematica side as--- lists, but of arbitrary length. Here, the Mathematica pattern--- would accept a list of zero or more numeric values.--- Notice that argumentPattern provides some preprocessing on the+-- lists, but, of course, of arbitrary length. Here, the Mathematica +-- pattern would match on a list of zero or more numeric values.+-- Notice that the argument pattern provides some preprocessing on the -- arguments, taking its real part and coercing the values to--- machine precision. This trick allows for a callPattern that+-- machine precision. This trick allows for a call pattern that -- matches more expressions, while still ensuring that on the -- Haskell side, the arguments have the desired, more specific, -- form when marshaled. reverseNumbersFunction = -  Function { callPattern = "ReverseNumbers[is___?NumericQ]"-           , argumentPattern = "N[Re[{is}]]"-           , function = reverseNumbers-           }---- Example 3: put a string.--- The first gives a list of single-character strings.--- The second, an atomic string.-greetWorld :: IO ()-greetWorld = do-  put ("Hello, world!", Ex.ExString "Hello, world!")--greetWorldFunction = -  Function { callPattern = "GreetWorld[]"-           , argumentPattern = ""-           , function = greetWorld-           }+  mkFunction "ReverseNumbers[is___?NumericQ]"+             "N[Re[{is}]]"+             reverseNumbers --- Example 4: get and put a 2D array, reversing its contents.+-- Example 3: get and put a 2D array, reversing its contents. -- NB: When marshaling in an array, make sure that you test for the -- array rank in callPattern to match that expected on the Haskell -- side, as below. Otherwise, you're likely to have the underlying  -- call to fromDimensions raise an error that halts the program.-reverseArray :: IO ()-reverseArray = do-  arr <- get-  let xs = elems (arr :: UArray (Int,Int) Int)-  put ((listArray (bounds arr) $ reverse xs) :: UArray (Int,Int) Int)+reverseArray :: UArray (Int,Int) Int -> IO (UArray (Int,Int) Int)+reverseArray arr = return $ listArray (bounds arr) $ reverse $ elems arr  reverseArrayFunction = -  Function { callPattern = "ReverseArray[a_?(ArrayQ[#,2,IntegerQ]&)]"-           , argumentPattern = "a"-           , function = reverseArray-           }+  mkFunction "ReverseArray[a_?(ArrayQ[#,2,IntegerQ]&)]"+             "a"+             reverseArray --- Example 5: gets an arbitrary Mathematica expression and returns ++-- Example 4: gets an arbitrary Mathematica expression and returns  -- a tweaked version of it.-tweakExpression :: IO ()-tweakExpression = do-  expr <- get-  put $ tweak expr+tweakExpression :: Expression -> IO Expression+tweakExpression expr = return $ tweak expr   where tweak ex =            case ex of-            Ex.ExInt i            -> Ex.ExInt (-i)-            Ex.ExReal r           -> Ex.ExReal (-r)-            Ex.ExString s         -> Ex.ExString $ reverse s-            Ex.ExSymbol s         -> Ex.ExSymbol $ reverse s-            Ex.ExFunction hd args -> Ex.ExFunction (reverse hd) $ map tweak args+            ExInt i            -> ExInt (-i)+            ExReal r           -> ExReal (-r)+            ExString s         -> ExString $ reverse s+            ExSymbol s         -> ExSymbol $ reverse s+            ExFunction hd args -> ExFunction (reverse hd) $ map tweak args  tweakExpressionFunction = -  Function { callPattern = "TweakExpression[expr_]"-           , argumentPattern = "expr"-           , function = tweakExpression-           }+  mkFunction"TweakExpression[expr_]"+            "expr"+            tweakExpression --- Example 6: use your own instance of Expressible+-- Example 5: use your own instance of Expressible data ExtendedComplex = Finite (Complex Double)                       | Infinity                        deriving (Eq,Show) -instance Ex.Expressible ExtendedComplex where+instance Expressible ExtendedComplex where     toExpression Infinity = -        Ex.ExSymbol "Infinity"+        ExSymbol "Infinity"     toExpression (Finite (r :+ i)) = -        Ex.ExFunction "Complex" [Ex.ExReal r,Ex.ExReal i]+        ExFunction "Complex" [ExReal r, ExReal i]     fromExpression expr =       case expr of-        Ex.ExFunction "DirectedInfinity" [_] -> +        ExFunction "DirectedInfinity" [_] ->            Right $ Infinity-        Ex.ExFunction "Complex" [Ex.ExReal r, Ex.ExReal i] -> +        ExFunction "Complex" [ExReal r, ExReal i] ->            Right $ Finite (r :+ i)-        _ -> Left $ Ex.ExpressibleErrorMsg $ +        _ -> Left $ ExpressibleErrorMsg $            "Unexpected expression: " ++ show expr -addExtendedComplexes :: IO ()-addExtendedComplexes = do-  (ec1,ec2) <- get+addExtendedComplexes :: (ExtendedComplex,ExtendedComplex) -> IO ExtendedComplex+addExtendedComplexes (ec1,ec2) =   case (ec1,ec2) of-    (Infinity,_) -> put Infinity-    (_,Infinity) -> put Infinity-    (Finite c1,Finite c2) -> put $ Finite (c1 + c2)+    (Infinity,_) -> return Infinity+    (_,Infinity) -> return Infinity+    (Finite c1,Finite c2) -> return $ Finite (c1 + c2)  addExtendedComplexesFunction = -  Function { callPattern = "AddExtendedComplexes[\+  mkFunction "AddExtendedComplexes[\                \ec1:(Infinity|Complex[_,_]),\                \ec2:(Infinity|Complex[_,_])]"-           , argumentPattern = "N[{ec1,ec2}]"-           , function = addExtendedComplexes-           }+             "N[{ec1,ec2}]"+             addExtendedComplexes --- Example 7: check for abort-abortTest :: IO ()-abortTest = do-  n <- (get :: IO Int)+-- Example 6: check for abort+abortTest :: Int -> IO Bool+abortTest n = do   liftIO $ timeout (100000*n) (bottom)-  checkAbort >>= put+  checkAbort   where bottom = (bottom :: IO ())  abortTestFunction = -  Function { callPattern = "AbortTest[i_Integer]"-           , argumentPattern = "i"-           , function = abortTest-           }+  mkFunction "AbortTest[i_Integer]"+             "i"+             abortTest  -- run mathlink exposing the given list of actions main = runMathLink [ addTwoFunction                    , reverseNumbersFunction-                   , greetWorldFunction                    , reverseArrayFunction                    , tweakExpressionFunction                    , addExtendedComplexesFunction
mathlink.cabal view
@@ -1,5 +1,5 @@ Name:                 mathlink-Version:              1.0.0.1+Version:              1.1.0.0 Cabal-Version:        >= 1.6 Build-Type:           Simple License:              BSD3
src/Foreign/MathLink.hs view
@@ -8,17 +8,14 @@                            -- $usage -                          -- * Types-                          Function(..)+                          -- * Exposing Functions+                          Function+                        , mkFunction                            -- * Running /MathLink/                         , runMathLink                         , runMathLinkWithArgs -                          -- * Data marshaling-                        , get-                        , put-                           -- * Accessing /MathLink/ state                         , getLink                         , checkAbort@@ -93,6 +90,14 @@                -- | The Haskell function to be invoked.              , function :: IO ()              }++mkFunction :: ( Expressible e1+              , Expressible e2+              ) => String -> String -> (e1 -> IO e2) -> Function+mkFunction cp ap fn = Function { callPattern = cp+                               , argumentPattern = ap+                               , function = get >>= fn >>= put+                               }  instance Show Function where     show fn = "Function { callPattern = " ++ 
src/Foreign/MathLink/Expressible.hs view
@@ -185,6 +185,12 @@     put = putWith putInt     get = getWith getInt +instance Expressible Word8 where+    toExpression = integralToExpression+    fromExpression = expressionToIntegral+    put = putWith putInt16+    get = getWith getInt16+ realFracToExpression :: RealFrac r => r -> Expression realFracToExpression = ExReal . realToFrac @@ -537,7 +543,13 @@     put = putListWith putDoubleList     get = getListWith getDoubleList +instance Expressible [Word8] where+    toExpression = listToExpression+    fromExpression = expressionToList+    put = putListWith putInt16List+    get = getListWith getInt16List + -- array marshaling  exprDimensions :: Expression -> [Int]@@ -687,6 +699,13 @@     get = getArrayWith getDoubleArray  instance ( Dimensional ix+         ) => Expressible (U.UArray ix Word8) where+    toExpression = arrayToExpression+    fromExpression = expressionToArray+    put = putArrayWith putInt16Array+    get = getArrayWith getInt16Array++instance ( Dimensional ix          ) => Expressible (A.Array ix Int8) where     toExpression = arrayToExpression     fromExpression = expressionToArray@@ -734,6 +753,13 @@     fromExpression = expressionToArray     put = putArrayWith putDoubleArray     get = getArrayWith getDoubleArray++instance ( Dimensional ix+         ) => Expressible (A.Array ix Word8) where+    toExpression = arrayToExpression+    fromExpression = expressionToArray+    put = putArrayWith putInt16Array+    get = getArrayWith getInt16Array  -- | Arrays to be marshaled to and from /Mathematica/ require indices --   that are instances of 'Dimensional'.