diff options
Diffstat (limited to 'lib/Data/Packed/Internal/Common.hs')
-rw-r--r-- | lib/Data/Packed/Internal/Common.hs | 24 |
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 | ||
16 | module Data.Packed.Internal.Common where | 17 | module 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@ | ||
38 | debug :: (Show a) => a -> a | ||
36 | debug x = trace (show x) x | 39 | debug x = trace (show x) x |
37 | 40 | ||
41 | -- | useful for expressions like @sortBy (compare \`on\` length)@ | ||
38 | on :: (a -> a -> b) -> (t -> a) -> t -> t -> b | 42 | on :: (a -> a -> b) -> (t -> a) -> t -> t -> b |
39 | on f g = \x y -> f (g x) (g y) | 43 | on 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]]@ | ||
41 | partit :: Int -> [a] -> [[a]] | 46 | partit :: Int -> [a] -> [[a]] |
42 | partit _ [] = [] | 47 | partit _ [] = [] |
43 | partit n l = take n l : partit n (drop n l) | 48 | partit 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 |
54 | infixl 0 // | 60 | infixl 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 | |
59 | errorCode :: Int -> String | 65 | errorCode :: Int -> String |
60 | errorCode 1000 = "bad size" | 66 | errorCode 2000 = "bad size" |
61 | errorCode 1001 = "bad function code" | 67 | errorCode 2001 = "bad function code" |
62 | errorCode 1002 = "memory problem" | 68 | errorCode 2002 = "memory problem" |
63 | errorCode 1003 = "bad file" | 69 | errorCode 2003 = "bad file" |
64 | errorCode 1004 = "singular" | 70 | errorCode 2004 = "singular" |
65 | errorCode 1005 = "didn't converge" | 71 | errorCode 2005 = "didn't converge" |
66 | errorCode n = "code "++show n | 72 | errorCode 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 |