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.hs24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/Data/Packed/Internal/Common.hs b/lib/Data/Packed/Internal/Common.hs
index 5548285..218fb6b 100644
--- a/lib/Data/Packed/Internal/Common.hs
+++ b/lib/Data/Packed/Internal/Common.hs
@@ -9,9 +9,10 @@
9-- Stability : provisional 9-- Stability : provisional
10-- Portability : portable (uses FFI) 10-- Portability : portable (uses FFI)
11-- 11--
12-- Common tools 12-- Development utilities.
13-- 13--
14----------------------------------------------------------------------------- 14-----------------------------------------------------------------------------
15-- #hide
15 16
16module Data.Packed.Internal.Common where 17module Data.Packed.Internal.Common where
17 18
@@ -33,11 +34,15 @@ instance (Storable a, RealFloat a) => Storable (Complex a) where --
33 poke p (a :+ b) = pokeArray (castPtr p) [a,b] -- 34 poke p (a :+ b) = pokeArray (castPtr p) [a,b] --
34---------------------------------------------------------------------- 35----------------------------------------------------------------------
35 36
37-- | @debug x = trace (show x) x@
38debug :: (Show a) => a -> a
36debug x = trace (show x) x 39debug x = trace (show x) x
37 40
41-- | useful for expressions like @sortBy (compare \`on\` length)@
38on :: (a -> a -> b) -> (t -> a) -> t -> t -> b 42on :: (a -> a -> b) -> (t -> a) -> t -> t -> b
39on f g = \x y -> f (g x) (g y) 43on f g = \x y -> f (g x) (g y)
40 44
45-- | @partit 3 [1..9] == [[1,2,3],[4,5,6],[7,8,9]]@
41partit :: Int -> [a] -> [[a]] 46partit :: Int -> [a] -> [[a]]
42partit _ [] = [] 47partit _ [] = []
43partit n l = take n l : partit n (drop n l) 48partit n l = take n l : partit n (drop n l)
@@ -50,19 +55,20 @@ common f = commonval . map f where
50 commonval [a] = Just a 55 commonval [a] = Just a
51 commonval (a:b:xs) = if a==b then commonval (b:xs) else Nothing 56 commonval (a:b:xs) = if a==b then commonval (b:xs) else Nothing
52 57
58-- | postfix function application (@flip ($)@)
53(//) :: x -> (x -> y) -> y 59(//) :: x -> (x -> y) -> y
54infixl 0 // 60infixl 0 //
55(//) = flip ($) 61(//) = flip ($)
56 62
57-- our codes should start from 1024 63-- GSL error codes are <= 1024
58 64-- | error codes for the auxiliary functions required by the wrappers
59errorCode :: Int -> String 65errorCode :: Int -> String
60errorCode 1000 = "bad size" 66errorCode 2000 = "bad size"
61errorCode 1001 = "bad function code" 67errorCode 2001 = "bad function code"
62errorCode 1002 = "memory problem" 68errorCode 2002 = "memory problem"
63errorCode 1003 = "bad file" 69errorCode 2003 = "bad file"
64errorCode 1004 = "singular" 70errorCode 2004 = "singular"
65errorCode 1005 = "didn't converge" 71errorCode 2005 = "didn't converge"
66errorCode n = "code "++show n 72errorCode n = "code "++show n
67 73
68{- | conversion of Haskell functions into function pointers that can be used in the C side 74{- | conversion of Haskell functions into function pointers that can be used in the C side