summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal/Common.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Internal/Common.hs')
-rw-r--r--lib/Data/Packed/Internal/Common.hs25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/Data/Packed/Internal/Common.hs b/lib/Data/Packed/Internal/Common.hs
index c3a733c..dc1c2b4 100644
--- a/lib/Data/Packed/Internal/Common.hs
+++ b/lib/Data/Packed/Internal/Common.hs
@@ -23,6 +23,8 @@ import Debug.Trace
23import Data.List(transpose,intersperse) 23import Data.List(transpose,intersperse)
24import Data.Typeable 24import Data.Typeable
25import Data.Maybe(fromJust) 25import Data.Maybe(fromJust)
26import Foreign.C.String(peekCString)
27import Foreign.C.Types
26 28
27---------------------------------------------------------------------- 29----------------------------------------------------------------------
28instance (Storable a, RealFloat a) => Storable (Complex a) where -- 30instance (Storable a, RealFloat a) => Storable (Complex a) where --
@@ -65,6 +67,13 @@ ww2 w1 o1 w2 o2 f = w1 o1 $ \a1 -> w2 o2 $ \a2 -> f a1 a2
65ww3 w1 o1 w2 o2 w3 o3 f = w1 o1 $ \a1 -> ww2 w2 o2 w3 o3 (f a1) 67ww3 w1 o1 w2 o2 w3 o3 f = w1 o1 $ \a1 -> ww2 w2 o2 w3 o3 (f a1)
66ww4 w1 o1 w2 o2 w3 o3 w4 o4 f = w1 o1 $ \a1 -> ww3 w2 o2 w3 o3 w4 o4 (f a1) 68ww4 w1 o1 w2 o2 w3 o3 w4 o4 f = w1 o1 $ \a1 -> ww3 w2 o2 w3 o3 w4 o4 (f a1)
67 69
70app1 f w1 o1 s = w1 o1 $ \a1 -> f // a1 // check s
71app2 f w1 o1 w2 o2 s = ww2 w1 o1 w2 o2 $ \a1 a2 -> f // a1 // a2 // check s
72app3 f w1 o1 w2 o2 w3 o3 s = ww3 w1 o1 w2 o2 w3 o3 $
73 \a1 a2 a3 -> f // a1 // a2 // a3 // check s
74app4 f w1 o1 w2 o2 w3 o3 w4 o4 s = ww4 w1 o1 w2 o2 w3 o3 w4 o4 $
75 \a1 a2 a3 a4 -> f // a1 // a2 // a3 // a4 // check s
76
68-- GSL error codes are <= 1024 77-- GSL error codes are <= 1024
69-- | error codes for the auxiliary functions required by the wrappers 78-- | error codes for the auxiliary functions required by the wrappers
70errorCode :: Int -> String 79errorCode :: Int -> String
@@ -78,6 +87,22 @@ errorCode 2006 = "the input matrix is not positive definite"
78errorCode 2007 = "not yet supported in this OS" 87errorCode 2007 = "not yet supported in this OS"
79errorCode n = "code "++show n 88errorCode n = "code "++show n
80 89
90-- | check the error code
91check :: String -> IO Int -> IO ()
92check msg f = do
93 err <- f
94 when (err/=0) $ if err > 1024
95 then (error (msg++": "++errorCode err)) -- our errors
96 else do -- GSL errors
97 ps <- gsl_strerror err
98 s <- peekCString ps
99 error (msg++": "++s)
100 return ()
101
102-- | description of GSL error codes
103foreign import ccall "auxi.h gsl_strerror" gsl_strerror :: Int -> IO (Ptr CChar)
104
105
81{- | conversion of Haskell functions into function pointers that can be used in the C side 106{- | conversion of Haskell functions into function pointers that can be used in the C side
82-} 107-}
83foreign import ccall "wrapper" mkfun:: (Double -> Ptr() -> Double) -> IO( FunPtr (Double -> Ptr() -> Double)) 108foreign import ccall "wrapper" mkfun:: (Double -> Ptr() -> Double) -> IO( FunPtr (Double -> Ptr() -> Double))